> 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/walkthrough/adding-navigation.md).

# Adding Navigation

So far we have tabbed app with 3 tabs, 2 of which support navigation. Here we are going to make use of `MvvmZero` to navigate to a `DetailPage`

We're going to make use of `CommandZero` for our `ICommand` implementation, but feel free to use your own if you have a favourite.

We'll start by adding an `ICommand` to the `SteadyPageVm` that pushes a `DetailPageVm` onto the stack.

Replace your `SteadyPageVm` with the following:

```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 initialise it with something.
            await _pageService.PushVmAsync<DetailPageVm>(vm => vm.Init("Initialise message from SteadyPageVm"));
        }
    }
}
```

This is standard `MVVM` and should be self explanatory.

In the above code we've chosen to call the `Init` method on our `DetailsPageVm` *each time* *we push it*, so now we'll add the `Init` method to the `DetailPageVm`, like this:

```csharp
namespace MvvmZeroTutorial.Mvvm.PageViewModels
{
    public class DetailPageVm : BasePageVm
    {
        private string _helloMessage;
        
        public string HelloMessage { get => _helloMessage;set=>SetProperty(ref _helloMessage, value); }
        
        internal void Init(string helloMessage)
        {
            HelloMessage = helloMessage;
        }
    }
}
```

Now we'll add a `Button` to our `SteadyPage` and bind it to our new `ICommand`

Replace the content of `SteadyPage.xaml` with the following:

```csharp
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MvvmZeroTutorial.Mvvm.Pages.SteadyPage"
             Title="SteadyPage">
    <VerticalStackLayout>
        <Label Text="Welcome to SteadyPage!" />
        <Button Text="{Binding PushDetailPageCommand.Text}" Command="{Binding PushDetailPageCommand}" />
    </VerticalStackLayout>
</ContentPage>
```

Also, we can add a `Label` to the `DetailPage.xaml` that displays the `Init` message passed in when the `PageViewModel` was pushed. Modify `DetailPage.xaml` like this:

```csharp
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MvvmZeroTutorial.Mvvm.Pages.DetailPage"
             Title="DetailPage">
    <VerticalStackLayout>
        <Label Text="Welcome to DetailPage!" />
        <Label Text="{Binding HelloMessage}"/>
    </VerticalStackLayout>
</ContentPage>
```

Do the same with the `GoPage` and we have a cross-platform app with a root `TabbedPage` and two navigation-stacks.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://functionzero.gitbook.io/docs/libraries/maui.mvvmzero/walkthrough/adding-navigation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
