Xamarin.Android binding throws System.InvalidOperationException: Property not found

Apr 20, 2015 at 3:08 PM
Edited Apr 20, 2015 at 3:09 PM
I already posted this on the Xamarin forums and on StackOverflow but answers have been non-existing so far. I'm hopping by posting here someone can finally help me.

I've used a few other MVVMLight bindings on my project and they have worked without problems but now I can't seem to get past this one.

After inflating the Fragment on its OnCreateView I save a bunch of controls that I want to bind to: some are LinearLayouts (who I want to hide based on the VM's property) and some are TextViews which I want to bind strings to.

On my search for a solution for this problem I stumbled upon someone that said that the View might not be inflated as the OnCreateView ends so my reference to that control could be wrong/null/not right. Therefore I moved my setBinding expressions to the OnActivityCreated method to at least "give it a little more time". Also, as per someone suggested, my views are all public properties in the Fragment.
pluginCodeLayoutBinding = this.SetBinding(
() => ViewModel.CreateMode,
() => pluginCodeLayout.Visibility,

pluginCodeBinding = this.SetBinding(
() => ViewModel.Script,
() => pluginCode.Text,
These bindings give out the following exceptions:
System.InvalidOperationException: Property not found: Visibility
System.InvalidOperationException: Property not found: Text

But when the execution breaks on the exception I'm able to inspect pluginCodeLayout and see that it has the Visibility property with it's default value.

Any help would be appreciated.

Thanks in advance!
Apr 21, 2015 at 12:31 PM
Note: This was cross-posted from your StackOverflow question
My team previously faced something similar and there's two things you can change in order for it to work:
  1. SetBinding directly in your previously fetched UI element (EditText or similar)
  2. Access your view model statically (since you're already using MVVM Light, I assume you have a ViewModelLocator already in place, which can be accessed from your App.cs)
We didn't have the time to dig deeper for a proper explanation (the implementation wasn't correct anw), that being said, the previous points translate to something similar to this in code:
var pluginCode = view.FindViewById<EditText>(Resource.Id.PluginCode);
     () => App.Locator.MyViewModel.SomeStringProperty,
     () => pluginCode.Text,
Don't forget to remove the bindings when you don't need them any more.