= Implementing Navigation Services in MVVM for Xamarin =
This technique uses !ViewModel first navigation which makes all the sense in the world if you are using MVVM. Otherwise, not so much. See: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/ for more details.
First, take a look at the attached [[attachment:XamarinNavigationExample.zip|project]]. It is a bare minimum implementation that shows:
1. How to set your initial page in app.xaml
1. How to implement the Navigation services and base classes.
What you want to know is how to add additional pages. The next section walks you through that process.
== Steps ==
1. Edit your App.xaml.cs file - See the [[https://scotnpatti.visualstudio.com/SimpleXamarinNavigation|project online]]
1. Create a Xaml view based on a !ContentPage. Name it [something]View.xaml
1. Create a !ViewModel inheriting from !ViewModelBase and Name it [something]!ViewModel.cs - yes naming conventions are important. Resolving views depends on it.
1. Make sure that the the binding context is setup correctly see the example below:
{{{#!highlight xml
}}}
1. Register the views in the ViewModelLocator.ViewModelLocator() in the services directory. E.g.
{{{#!highlight csharp
static ViewModelLocator()
{
_container = new TinyIoCContainer();
_container.Register();
...
}
}}}
1. Add "navigate to" code to the appropriate ViewModels.