> For the complete documentation index, see [llms.txt](https://functionzero.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://functionzero.gitbook.io/docs/libraries/maui.mvvmzero/quickstart.md).

# Quickstart

Configure `MauiProgram.cs` and launch in `App.xaml.cs`

#### MauiProgram.cs

In `MauiProgram.cs` configure `MvvmZero` and your container.

```csharp
namespace SampleTabbedApp
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                *******************************
                *** CONFIGURE MVVMZERO HERE ***
                *******************************
                )
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });

#if DEBUG
            builder.Logging.AddDebug();
#endif
            ********************************
            *** CONFIGURE CONTAINER HERE ***
            ********************************

            return builder.Build();
        }
    }
}
```

#### Configure `MvvmZero`

```csharp
.UseMauiApp<App>()
.UseMvvmZero(
serviceBuilder =>
{
    // Configure MvvmZero ...
    serviceBuilder
    .MapVmToView<ReadyPageVm, ReadyPage>()      // Visualise a ReadyPageVm in a ReadyPage
    .MapVmToView<SteadyPageVm, SteadyPage>()
    .MapVmToView<GoPageVm, GoPage>();
    ...
}
```

#### Configure your container

Register all your Pages and ViewModels in the Container.

`MvvmZero` registers `IPageService` and `NavigationPage` in the container for you.\
Unless you override the `TypeFactory` everything else `MvvmZero` is asked to instantiate **must** be registered in the container.\
This includes `FlyoutPage` and `TabbedPage` if you use them.

```csharp
builder.Services
    // The root page is supplied by the container!
    // AdaptedTabbedPage Because https://github.com/dotnet/maui/issues/14572
    .AddSingleton<MultiPage<Page>, AdaptedTabbedPage>()

    .AddSingleton<ReadyPage>()
    .AddSingleton<SteadyPage>()
    .AddSingleton<GoPage>()

    .AddSingleton<ReadyPageVm>()
    .AddSingleton<SteadyPageVm>()
    .AddSingleton<GoPageVm>()

    // DetailPage/Vm are transient because there can be more than one on any navigation stack at any time.
    .AddTransient<DetailPage>()
    .AddTransient<DetailPageVm>()
    ;
```

#### App.xaml.cs

In `App.xaml.cs`

```csharp
public partial class App : Application
{
    public App(IPageServiceZero pageService)
    {
        InitializeComponent();
            
        pageService.Init(this);     // Required!

        // This app has a TabbedPage containing 3 tabs at the root.
        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;
    }
}
```

To navigate from within a `ViewModel` use the `IPageServiceZero` implementation:

```csharp
_pageService.PushVmAsync<TViewModel>(Action<TViewModel> initViewModelAction);
```

Like this:

```csharp
using FunctionZero.CommandZero;
using FunctionZero.Maui.MvvmZero;
using System.Windows.Input;

namespace MvvmZeroTutorial.Mvvm.PageViewModels
{
    public class SteadyPageVm : BasePageVm
    {
        private readonly IPageServiceZero _pageService;

        public ICommand PushDetailPageCommand { get; }

        public SteadyPageVm(IPageServiceZero pageService)
        {
            _pageService = pageService;

            PushDetailPageCommand = new CommandBuilder()
                                        .AddGuard(this)
                                        .SetName("Push Detail Page")
                                        .SetExecuteAsync(PushDetailPageExecuteAsync)
                                        .Build();
        }

        private async Task PushDetailPageExecuteAsync()
        {
            // Push a page and tell it what pushed it.
            await _pageService.PushVmAsync<DetailPageVm>(vm => vm.Init("Initialise message from SteadyPageVm"));
        }
    }
}

```
