I first used MvvmCross with Windows Phone 8, and XAML has a pretty good data-binding syntax already in place.

Switching over to Android, though, and the data binding didn't seem as straightforward. I was struggling just to bind a Button to an IMvxCommand.

So I checked out the MvvmCross documentation on Databinding (which, by the way, makes it seem like databinding is still very much a work in progress in MvvmCross), and I came across the idea of "Fluent Databinding" (as opposed to "Swiss Databinding", I guess). Instead of doing the binding in the AXML Android view markup, I could just do it in C# in the Android activity. Here's an example of binding a Button click event to an IMvxCommand in the viewmodel:

Note that the .For("Click") clause is actually optional, since "Click" seems to be the "default view property". But I chose to be explicit, especially for this example.

Comments

Please enable JavaScript to view the comments powered by Disqus.