Root TabbedPage

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 this Maui bug 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 Getting Started 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.

Last updated