xamarin page navigation mvvm code example

Example 1: Navigate Handled in viewModel Xamarin

namespace YourApp.ViewModels
{
    public class CurrentPageViewModel
    {
        public ICommand BackToPage  {get; private set; }

        public CurrentPageViewModel()
        {
            BackToPage = new Command(async () => {
              await  Application.Current.MainPage.Navigation.PushModalAsync(new MainPage());
            });
        }
    }
}

Example 2: Navigate Handled in viewModel Xamarin

namespace RealmApp1.Views
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            BindingContext = new MainPageViewModel();
        }      
    }
}

Tags:

Misc Example