xamarin.ios - Mvvmcross bind to Visibility with autolayout and fully hide view -


currently binding "visibility" sets hidden=true. how create generic visibility binding changes constraint: sets view height 0 ?

for tutorial on creating bindings, see n=28 video on http://mvvmcross.blogspot.com/

to replace existing visibility binding, create own class based on https://github.com/mvvmcross/mvvmcross/blob/v3.1/cirrious/cirrious.mvvmcross.binding.touch/target/mvxuiviewvisibletargetbinding.cs

public class myuiviewvisibletargetbinding : mvxbaseuiviewvisibletargetbinding {     public myuiviewvisibletargetbinding(uiview target)         : base(target)     {     }      protected override void setvalueimpl(object target, object value)     {         var view = view;         if (view == null)             return;          var visible = value.converttoboolean();         // code here         // - in place of or in addition to:         // view.hidden = !visible;     } } 

and register last step in setup using:

protected override void initializelastchance() {      base.initializelastchance();       var registry = mvx.resolve<imvxtargetbindingfactoryregistry>();      registry.registercustombindingfactory<uiview>("visible",                                                     view =>                                                     new myuiviewvisibletargetbinding(view)); 

}

for more on replacing existing bindings, see mvvmcross binding decimal uitextfield removes decimal point


note if want replace visible bindings, might want replace of visible, visibility , hidden - see registrations in https://github.com/mvvmcross/mvvmcross/blob/v3.1/cirrious/cirrious.mvvmcross.binding.touch/mvxtouchbindingbuilder.cs#l42


Comments