MVVM and Data Binding

In the previous chapter, we created a cross-platform Xamarin.Forms application for both iOS and Android platforms, and then created a data model that stored information relating to walking trails used by our application. We then created a number of content pages using XAML that were populated with static data using our data model. Finally, we looked at how to use the navigation APIs included as part of the Xamarin.Forms platform to help navigate between each of the different content pages, before running the TrackMyWalks application within the iOS Simulator.

The Model-View-ViewModel (MVVM) architectural pattern was invented with the XAML in mind, which was created by Microsoft back in 2008. It is well-suited for use with the MVVM architectural pattern, as it enforces a separation of the XAML user interface from the underlying data model, through a class that will act as a connection between the View and the ViewModel, which can be connected through data bindings, which have been defined within the XAML file.

This chapter teaches you the concepts behind the MVVM architectural pattern, as well as how to implement the MVVM architectural pattern within the TrackMyWalks application. You'll learn how to create a BaseViewModel base class that every ViewModel will inherit from, as well as create the associated C# class files for each of our ViewModels that will data-bind to each of the properties defined within our XAML pages.

The associated properties that we define within the ViewModel for the ContentPage will be used to represent the information that will be displayed within the user interface for our application. We will learn how to add ContextActions to our XAML content pages, and how to implement the code action events within our code, so that we can respond to those actions.

This chapter will cover the following topics:

  • Understanding the MVVM architectural pattern as well as data binding
  • Creating and implementing the Base-Model class that the ViewModels will inherit
  • Updating the user interface pages using XAML to include data binding
  • Creating and implementing the underlying ViewModels using C# code
  • Implementing the data bindings within our user interfaces using XAML
  • Launching the TrackMyWalks app using the iOS Simulator
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.194.57