Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of local:MvxBind binders

I couldn't find a list of all type of binders available for use, recently a collegue found about local:MvxBind="Visibility Property" and that helped a lot with our code. I belive that MvvMCross has a lot of hidden gems that we don't know yet. Is the information available somewhere?

Binders that we know:

  • local:MvxBind="Text Property"
  • local:MvxBind="ItemsSource Property; SelectedItem Property"
  • local:MvxBind="Click ICommandProperty"
  • local:MvxBind="ItemsSource Property; ItemClick ICommandProperty"
  • local:MvxBind="Visibility Property"

Thanks!

like image 221
Rafael Matos Avatar asked Nov 22 '13 19:11

Rafael Matos


1 Answers

Automatic Property Binding

MvvmCross binds to C# properties on native Views - so any public C# get/set property exposed by Xamarin.Android can be one-way bound to.

Further, if the property Foo is accompanied by an event of signature public event EventHandler FooChanged then MvvmCross can two-way bind to it.


Automatic Event Binding

MvvmCross also binds to any public C# events which are exposed by native views - as long as they have EventHandler signatures and not EventHandler<SomeSpecialArgs>

These can be automatically bound to ICommand callers (the action is automatically bound to the Execute handler, but nothing is automatically bound to the CanExecute).


Custom Binding

Beyond these straight-forward properties, MvvmCross also has facilities for "custom bindings".

The list of "custom bindings" that MvvmCross supplied by default is in FillTargetBindings in AndroidBindingBuilder - https://github.com/MvvmCross/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/MvxAndroidBindingBuilder.cs#L79

        registry.RegisterCustomBindingFactory<TextView>("Text",
                                                        textView => new MvxTextViewTextTargetBinding(textView));
        registry.RegisterPropertyInfoBindingFactory((typeof(MvxAutoCompleteTextViewPartialTextTargetBinding)),
                                                typeof(AutoCompleteTextView), "PartialText");
        registry.RegisterPropertyInfoBindingFactory(
                                                typeof(MvxAutoCompleteTextViewSelectedObjectTargetBinding),
                                                typeof(AutoCompleteTextView),
                                                "SelectedObject");
        registry.RegisterPropertyInfoBindingFactory(typeof(MvxCompoundButtonCheckedTargetBinding),
                                                typeof(CompoundButton), "Checked");
        registry.RegisterPropertyInfoBindingFactory(typeof(MvxSeekBarProgressTargetBinging), typeof(SeekBar),
                                                "Progress");
        registry.RegisterCustomBindingFactory<View>("Visible",
                                                        view => new MvxViewVisibleBinding(view));
        registry.RegisterCustomBindingFactory<View>("Hidden",
                                                        view => new MvxViewHiddenBinding(view));
        registry.RegisterCustomBindingFactory<ImageView>("Bitmap",
                                                        imageView => new MvxImageViewBitmapTargetBinding(imageView));
        registry.RegisterCustomBindingFactory<ImageView>("DrawableId",
                                                        imageView => new MvxImageViewDrawableTargetBinding(imageView));
        registry.RegisterCustomBindingFactory<ImageView>("DrawableName",
                                                        imageView => new MvxImageViewDrawableNameTargetBinding(imageView));
        registry.RegisterCustomBindingFactory<ImageView>("AssetImagePath",
                                                         imageView => new MvxImageViewImageTargetBinding(imageView));
        registry.RegisterCustomBindingFactory<MvxSpinner>("SelectedItem",
                                                                         spinner =>
                                                                         new MvxSpinnerSelectedItemBinding(
                                                                             spinner));
        registry.RegisterCustomBindingFactory<AdapterView>("SelectedItemPosition",
                                                                          adapterView =>
                                                                          new MvxAdapterViewSelectedItemPositionTargetBinding
                                                                              (adapterView));
        registry.RegisterCustomBindingFactory<MvxListView>("SelectedItem",
                                                                          adapterView =>
                                                                          new MvxListViewSelectedItemTargetBinding
                                                                              (adapterView));
        registry.RegisterCustomBindingFactory<RatingBar>("Rating",
                                                        ratingBar => new MvxRatingBarRatingTargetBinding(ratingBar));
        registry.RegisterCustomBindingFactory<View>("LongClick",
                                                        view =>
                                                        new MvxViewLongClickBinding(view));
        registry.RegisterCustomBindingFactory<MvxRadioGroup>("SelectedItem",
            radioGroup => new MvxRadioGroupSelectedItemBinding(radioGroup));

A couple of the plugins (notably Color) also add their own bindings.

For information on adding your own custom bindings, see http://slodge.blogspot.co.uk/2013/06/n28-custom-bindings-n1-days-of-mvvmcross.html

The N+1 topics on MvvmCross custom controls, on animation and on maps are also worth watching - they provide alternative mechanisms to custom bindings.

For more on MvvmCross binding, see https://github.com/MvvmCross/MvvmCross/wiki/Databinding

like image 80
Stuart Avatar answered Oct 15 '22 05:10

Stuart