Paul Michaels
Paul Michaels

Reputation: 16685

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?

Upvotes: 1

Views: 297

Answers (2)

Steve Chadbourne
Steve Chadbourne

Reputation: 6953

Are you using any particular MVVM framework? Most of these include a way of navigating from VM to VM.

I use FreshMvvm. It allows you to perform the following to navigate between VMs and also pass data:

CoreMethods.PushPageModel<MyNextPageModel>(DataToPass);

More details here

Upvotes: 1

Ricardo Romo
Ricardo Romo

Reputation: 1624

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...

Upvotes: 1

Related Questions