简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM