Search code examples
c#iosxamarinmvvmcross

MVVMCross, FieldBinding plugin, iOS, code binding doesn't work


I'm using MVVMCross/Xamarin in my iOS application. I have ViewModel with property defined like this:

public readonly INC<Address> Entity = new NC<Address>();

where

public class Address
{
    public string Line1 { get; set; }

    public string Line2 { get; set; }

    public string Line3 { get; set; }
    //other properties...
}

If I do binding this way, it works:

set.Bind(Line1Text).To("Entity.Line1").TwoWay();

If I do binding this way, it doesn't work and outputs warning (see below):

set.Bind(Line1Text).To(vm => vm.Entity.Value.Line1).TwoWay();

The error I get is that binding is not constructed. The warning from application output:

2014-10-08 19:12:15.341 IosTemplate[8442:248933] MvxBind: Warning: 12.63 Unable to bind: source property source not found Property:Value on Address

Please advise, how to do a binding with INC/NC with lambda expression way.


Solution

  • Please advise, how to do a binding with INC/NC with lambda expression way

    The Field Binding plugin doesn't ship with any extensions to the fluent expression parsing so this type of chained expression can't be done in fluent form without additional work.

    If you wanted to extend either the way the fluent binding expression is parsed or the way the binding is evaluated - to add some special cases for INC - then I believe this could be done, but it would require some experimentation and coding to do it. For example, you could experiment with inspecting and manipulating the childList in https://github.com/MvvmCross/MvvmCross/blob/3.2/Plugins/Cirrious/FieldBinding/Cirrious.MvvmCross.Plugins.FieldBinding/MvxChainedNotifyChangeFieldSourceBinding.cs#L32 in order to remove Value items from the list - although this might remove the occasional correct Value too :/ If you can get something working well and reliably, then would be very happy to accept that back into the framework as a pull request too.