# 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"));
        }
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://functionzero.gitbook.io/docs/libraries/maui.mvvmzero/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
