FunctionZero
  • Libraries
    • Maui.MvvmZero
      • Overview
      • Quickstart
      • Walkthrough
        • Create your application
        • Create your ContentPages
        • Create your ViewModels
        • Register your new content
        • Launching our app!
        • Adding Navigation
        • Summary
      • Recommended naming conventions
      • Configuring your root Page
        • Root ContentPage
        • Root NavigationPage
        • Root TabbedPage
        • Root FlyoutPage
      • A note on Singleton vs Transient
      • Recommended base classes for PageViewModels and ViewModels
    • Maui.Controls
      • ExpanderZero
      • FocusScrollZero
      • LabelZero
      • ListViewZero
      • MaskZero
      • MultiViewZero
      • TreeViewZero
    • CommandZero
    • Maui.BindZero
      • Quickstart
      • z:Bind
      • Examples
      • The Great Escape
      • Casting
      • Short Circuit
      • Errors
      • Aliases
      • Value types and Reference types
      • z:Function
      • z:TapTrigger
      • z:EdgeTrigger
      • z:Latch
      • Advanced Usage - Functions, aliases and operator-overloads
    • AnimationZero
    • LocalisationZero
Powered by GitBook
On this page
  1. Libraries
  2. Maui.MvvmZero
  3. Configuring your root Page

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.

PreviousRoot ContentPageNextRoot TabbedPage

Last updated 1 year ago