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 TabbedPage

PreviousRoot NavigationPageNextRoot FlyoutPage

Last updated 1 year ago

A little bit more work is necessary for a TabbedPage, and IPageServiceZero is here to help!

First we'll need to register our TabbedPage in the container. Add the following line to our registrations in MauiProgram.cs:

.AddSingleton<MultiPage<Page>, AdaptedTabbedPage>()

Note we're using an AdaptedTabbedPage instead of TabbedPageuntil is fixed

We'll also need to register the pages and viewmodels the TabbedPage is going to present, as well as the mappings from vm to page. See the section for a walkthrough

Once we've registered everything in the container, this is how we configure and launch the app:

using FunctionZero.Maui.MvvmZero;
using MvvmZeroTutorial.Mvvm.PageViewModels;

namespace MvvmZeroTutorial
{
    public partial class App : Application
    {
        public App(IPageServiceZero pageService)
        {
            InitializeComponent();
            
            // Don't forget to call pageService.Init, or navigation will not work properly!
            pageService.Init(this);
            
            MainPage = pageService.GetMultiPage(VmInitializer, typeof(ReadyPageVm), typeof(SteadyPageVm), typeof(GoPageVm));
        }

        private bool VmInitializer(object viewModel)
        {
            if (viewModel is ReadyPageVm)
                return false; // Do not wrap the ReadyPage in a NavigationPage.

            return true;
        }
    }
}

Simple.

this Maui bug
Getting Started