0
votes

This is actually pretty trivial thing, however, I've bumped into it already several times and every new time was spending plenty of minutes to find out why such simple binding to properties (with MvvmCross) does not work! So, I hope that would help anyone.

The situation (is pretty simple): (just a view with some property I am going to bind to ViewModel (in this example - for Touch)).

public class MyView : MvxViewController
{
    protected string SomeValue
    {
        get; set;
    }

    private void SomeInitializationMethod()
    {
        var set = this.CreateBindingSet<MyView, MyViewModel>();
        // binding to "this"
        set.Bind().For(x => x.SomeValue).To(x => x.ViewModelSomeValue);
        set.Apply();
    }
}

So, in this case the property does not bind and you can see "Failed to create target binding for from ViewModelSomeValue to CurrentContacts" message.

1

1 Answers

0
votes

So, the cause of the problem is just some simple word: "public". As MvvmCross uses reflection for databinding, it expects the property to bind to is public and honestly says "I could not get to it".

protected string SomeValue
{
    get; set;
}

That happened for me several time just because of Resharper using and it was adding the property modifier automatically to "protected".

Good luck!