Search code examples
c#xamarinmvvmxamarin.formsicommand

Navigation between pages in Xamarin Forms


I have the following command inside a VM:

ICommand LaunchGameCommand => new Command(() =>
{
    //Navigation.PushAsync(...
});

According to the answers here I should be able to use something akin to the navigation in the commented code; however, the Navigation object seems to reside in Android.Content.Res... which seems to be something else entirely.

Is this still the correct method of navigating between views / viewmodels in Xamarin Forms, or has this now been superseded with an alternate method?


Solution

  • Navigation is part of a page, you can’t find navigation property if you don’t have the reference to a some page, you need to have access to your current page in your view model to see this property, you can have access to your current page using

    Application.Current.MainPage.Navigation.Push...