The course is part of this learning path
This course looks at the Xamarin Forms implementation of the Model-View-ViewModel architecture, paying special attention to data and command binding. We see how to bind view models and nested models to views, and explore notification mechanisms built into the Xamarin Forms core for bi-directional data and view updating. The course also looks at XAML markup extensions and value converters for displaying images within a Xamarin Forms app.
Learning Objectives
Understand the model and view model aspects of MVVM and create an application using the Flyout app template
Intended Audience
This course is designed for anyone interested in enhancing their knowledge of Xamarin, with a focus on MVVM.
Prerequisites
To get the most from this course, you should have a basic understanding of interfaces and reflection in the context of C# and .NET.
Source Code
Model-View-ViewModel is a development framework and methodology designed to better structure projects by separating presentation, business logic, and data layers. Binding is a key mechanism for coordinating the flow of data and commands between the view and view model layers. Xamarin Forms is designed around the MVVM framework, and much of the binding functionality is baked into the core Xamarin libraries. In XAML, data-binding syntax in its simplest form is enclosed within curly braces with the keyword Binding referencing public members of the view model class specified as the binding context. Data can flow from the view to the view model or vice versa. You can explicitly specify data flow behavior with the binding mode keyword. The public members of complex data types can be bound using the dot syntax. Almost any object can be bound to a UI control if it is converted into the correct format. You can define methods for data conversion and reference them within XAML. This can be achieved by implementing the IMarkupExtension or IValueConverter interfaces.
Whether data or command, binding only works between bindable controls and objects that support the INotifyPropertyChanged interface. Behind the scenes, .Net uses reflection to inspect views and classes for binding associations. When a view detects the user has changed a field, it first assesses whether the field is bound. If it is, then the object's public members specified in the view's binding context are searched for the one bound to the control. Once found, the binding context object's data is updated accordingly. As a developer, you can trigger a UI update by invoking PropertyChanged with the name of the public member. Reflection will work in the other direction, searching the associated view for a control bound to that public member.
We've covered a lot of ground in this Xamarin Forms MVVM course. I highly recommend downloading the source code from Github and going through it. Modify the code and see how the behavior and appearance change. Don't be afraid to break it and fix it. You learn by doing. My name is Hallam Webber, and I hope you've enjoyed this course.
Hallam is a software architect with over 20 years experience across a wide range of industries. He began his software career as a Delphi/Interbase disciple but changed his allegiance to Microsoft with its deep and broad ecosystem. While Hallam has designed and crafted custom software utilizing web, mobile and desktop technologies, good quality reliable data is the key to a successful solution. The challenge of quickly turning data into useful information for digestion by humans and machines has led Hallam to specialize in database design and process automation. Showing customers how leverage new technology to change and improve their business processes is one of the key drivers keeping Hallam coming back to the keyboard.