Writing my login page in IOS Droid using MVVMCross.
this is what I have so far
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 binding of 'UserName' successfully binds to the UsernameTextField. However, when the LoginCommand is fired (excluded for brevity) I wan't UI control to be set as 'Enabled = false' whilst the login routine is in progress.
The code above fails at run-time at the x.Enabled binding, with
System.ArgumentException: Property expression must be of the form 'x => x.SomeProperty.SomeOtherProperty'
I must be writing the binding incorrectly, as I DO wish to bind to the 'Enabled' property directly, and not a child prop - but i can't quite see how to do this.
I have looked around some of the samples on mvvmcross, and have looked through a few N+1 videos but I can't seem to find a sample matching enabled, or another child property binding.
Thanks
I couldn't see what was wrong with your code - but I just tried https://github.com/slodge/Enabling and that seemed to work...
So I took another look ... and the problem isn't in the Enabled - instead it is in:
To(x => !x.LoggingIn)
That is not a simple property expression - it's got the !
operator there.
Instead of using !
you can use a ValueConverter like:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With