xamarin forms viewmodel navigation code example
Example 1: Navigate Handled in viewModel Xamarin
namespace YourApp.ViewModels
{
public class MainPageViewModel
{
public ICommand BackToMain { get; private set; }
public MainPageViewModel()
{
BackToMain = new Command(async () => {
await Application.Current.MainPage.Navigation.PopAsync();
});
}
}
}
Example 2: Navigate Handled in viewModel Xamarin
namespace RealmApp1.Views
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageViewModel();
}
}
}