Differences between the Navigation and ViewModel approaches

In this section, we will take a look at the different approaches when performing navigation within your ViewModels that are contained within a Xamarin.Forms application. Whenever you navigate between your ViewModels, there are a couple of approaches you should consider before going down this path.

One approach would be to use the View (Page) navigation approach, which involves navigating to another View by using a direct reference to that page, for example, using Navigation.PushAsync(new WalksMainPage());. Alternatively, if you want to use the ViewModel approach to navigate to a View (Page) using the associated Views (Page) ViewModel, you would first need to form some sort of mapping between each of the Views (Page) as well as their associated ViewModels.

By creating a Dictionary or key-value type property within the NavigationService, this will maintain a one-to-one mapping for each of the Views and their associated ViewModel. In the MVVM architectural pattern, any actions that are taken by the user on a particular View (Page) are bound to commands that are part of the View (Page), as well as the ViewModels, and so this process needs to be thought through differently when navigating to another View (Page), or even the previous View (Page) within the navigation stack, when performing such tasks as saving data or updating a map's location.

As such, we need to rethink how we can achieve navigating through our ViewModels, which leverages the MVVM architectural design pattern within our app, so that it can be controlled by the ViewModels and not by the underlying Views (Pages).

Now that you have a good understanding of the different ways in which you can navigate through your Views (Pages), by either using the Navigation approach or using the ViewModel approach that leverages the MVVM architectural design pattern approach, our next step is to begin creating and implementing the NavigationService class, which will be used to help you navigate within the ViewModels for our TrackMyWalks application.

..................Content has been hidden....................

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