How to associate the "enabled" property of a monotouch UI element with a boolean viewmodel in Mvvmcross

Record my iOS Droid login page using MVVMCross.

that's what i still

var bindingSet = this.CreateBindingSet<LoginPageView, LoginPageViewModel>(); bindingSet.Bind(this.UsernameTextField).To(x => x.UserName).TwoWay(); bindingSet.Bind(this.UsernameTextField).For(x=>x.Enabled).To(x => !x.LoggingIn); bindingSet.Apply(); 

The bind "UserName" successfully binds to UsernameTextField. However, when LogCommand is fired (excluded for brevity), I have to configure the UI element as "Enabled = false" while the login procedure is in progress.

The above code does not execute at runtime when binding x.Enabled, with

 System.ArgumentException: Property expression must be of the form 'x => x.SomeProperty.SomeOtherProperty' 

I have to write the wrong binding, since I DO NOT want to bind to the "Enabled" property, and not to the child support, but I cannot figure out how to do this.

I looked at some samples on mvvmcross and watched several N + 1 videos, but I cannot find a suitable match for the sample or another binding of the child property.

thanks

+6
source share
1 answer

I couldn't figure out what was wrong with your code, but I just tried https://github.com/slodge/Enabling and it seemed to work ...

So, I took another look ... and the problem is not Enabled - instead, it is in:

  To(x => !x.LoggingIn) 

This is not just a property expression - he got an operator there ! .

Instead of using ! you can use ValueConverter, for example:

  public class InverseValueConverter : MvxValueConverter<bool, bool> { protected override bool Convert(bool value, ...) { return !value; } } 

Then:

  bindingSet.Bind(this.UsernameTextField) .For(x=>x.Enabled) .To(x => x.LoggingIn) .WithConversion(new InverseValueConverter(), null); 
+10
source

Source: https://habr.com/ru/post/954405/


All Articles