Skip to main content

MvvmCross Fluent Databinding

March 18, 2014 mgroves 0 Comments
Tags: xamarin csharp mvvmcross

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

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter