user1180360
user1180360

Reputation: 43

Maui Navigating to tabbar. No back button

I have the following appshell

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="myApp.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:myApp.Pages"
    Shell.FlyoutBehavior="Disabled"
    Title="myApp">


    <ShellContent
        Title="Home"
        ContentTemplate="{DataTemplate local:HomePage}"
        />

    <TabBar x:Name="theTabBar" Route="itemDetails" Title="Item Details" NavigationPage.HasNavigationBar="True">

        <Tab Title="Details" Icon="details.png">
            <ShellContent ContentTemplate="{DataTemplate local:DetailPage}" />
        </Tab>
        <Tab Title="Notes" Icon="notes.png">
            <ShellContent ContentTemplate="{DataTemplate local:NotesPage}" />
        </Tab>

    </TabBar>


</Shell>

When the app starts the home page is loaded correctly. From the home page, a user can navigate to a list page and from there to the detail page (TabBar).

My problem is that there is no backbutton when the detail page is shown. Clicking on Android Back hides the app.

I am porting from Xamarin and the app uses the previous TabbedPage to show lots of detail (very data intensive). I cannot use this with Shell Navigation so am trying to get TabBar to work. Quite frustrated at this stage and would appreciate any pointers.

Upvotes: 1

Views: 936

Answers (1)

H.A.H.
H.A.H.

Reputation: 3897

Each tab in the TabBar has its own navigation stack.

On the bottom of it, stays the Tab itself. Clicking the button back, tries to remove a page from the stack. When you are only with the tab left, the program closes.

You can switch tab(stacks) with triple slash navigation. https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation?view=net-maui-8.0#relative-routes

So, the short answer is: you can not go back. This is not working like "TabbedPage", because it is not even a page in the stack. It is new, separate stack.

The long answer: you can always implement your custom navigation logic. Each time you navigate, you can save your last position. And then override the default back button behavior. (Then again, if your users have other MAUI programs, and are used to the default behavior, will they be happy that you implemented something that behaves completely different?)

Upvotes: 0

Related Questions