Using data-binding and MVVM
At this point, you should be grasping the basics of Xamarin.Forms, but are wondering how the MVVM design pattern fits into the picture. The MVVM design pattern was originally conceived for use along with XAML and the powerful data binding features XAML provides, so it is only natural that it is a perfect design pattern to be used with Xamarin.Forms.
Let's cover the basics of how data-binding and MVVM is set up with Xamarin.Forms:
- Your Model and ViewModel layers will remain mostly unchanged from the MVVM pattern we covered earlier in the book.
- Your ViewModels should implement the
INotifyPropertyChanged
interface, which facilitates data binding. To simplify things in Xamarin.Forms, you can use theBindableObject
base class and callOnPropertyChanged
when values change on your ViewModels. - Any
Page
or control in Xamarin.Forms has aBindingContext
, which is the object that it is data-bound to. In general, you can set a corresponding ViewModel to each view's...