Root NavigationPage
A common scenario is to use a NavigationPage
as the MainPage
. This allows stack-based navigation in your application
The goal here is to get a reference to a NavigationPage
, push our root-page onto it, and assign the result to App.MainPage
IPageServiceZero
and NavigationPage
are registered in the container for us, we will have to register our pages and viewmodels ourselves:
using FunctionZero.Maui.MvvmZero;
using SampleApp.Mvvm.Pages;
using SampleApp.Mvvm.PageViewModels;
namespace SampleApp
{
public partial class App : Application
{
public App(NavigationPage navPage, IPageServiceZero pageService)
{
InitializeComponent();
// Don't forget to call pageService.Init, or navigation will not work properly!
pageService.Init(this);
MainPage = navPage;
pageService.PushPageAsync<HomePage, HomePageVm>(vm => vm.Init("Main screen turn on"));
}
}
}
Simple.
Last updated