How to correctly use shell navigation in a maui project?

John Li 0 Reputation points
2025-02-12T22:56:17.7566667+00:00

I am using MVVM for project. I have a page (BuildingOverViewPage) that displays a list of buildings in my app, and i also have another page (ViewEditBuildingPage) that handles View/Add/Edit building. I am using shell navigation. However, the navigation is not quite what i want, and i dont know how to fix it.

In the flyout, i have a shellcontent that points to my BuildingOverViewPage

<ShellContent
    Title="Building"
    ContentTemplate="{DataTemplate views:BuildingOverviewPage}"
    FlyoutIcon="{mi:Material Icon=Apartment,
                             IconColor={AppThemeBinding Dark={StaticResource White},
                                                        Light={StaticResource Black}},
                             IconAutoScaling=True}"
    Route="BuildingOverviewPage" />

In the code behind shell, i also have this page registered as a global route

Routing.RegisterRoute("buildingoverview",typeof(BuildingOverviewPage));

In ViewEditBuildingPage viewmodel, i use a async method to control where each mode should go back by using BackButtonBehavior.

[RelayCommand]
async Task GoBackAsync()
{
    if (Purpose == "Add" || Purpose == "Edit")
    { 
        await Shell.Current.GoToAsync("..");
    }
    if (Purpose == "View")
    {
        await Shell.Current.GoToAsync("buildingoverview");
    }
}

This is my setup. When i navigate from flyout to my building overview page, the flyout hamburger icon is still there. However, when i navigate to a view page or edit/add page, and back to building overview page, the hamburger icon turns into a back arrow, and that back arrow navigates me back to the previous view/edit/add page. I want the hamburger icon to stay whenever i am on the building overview page. Is it possible?

Screenshot 2025-02-12 175450

Screenshot 2025-02-12 175040

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,919 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.