Shell navigate to same page from more other pages

In my .net maui app I have a help page, called "AboutHelp", that I want to navigate to from more other pages. How do I do that ? My problem is that the Back arrow button doesn't work when I navigate to the AboutHelp page from other than the Main page, "MainPage".

If I navigate to a page I called "ControlPanel" with the command


[RelayCommand]
public async Task ControlsButton_Clicked()
{
    var prams = new Dictionary<string, object>
    {
        {
            "BtnSaveAllRawTxtAsIsEnbled"
            ,
            BtnSaveAllRawTxtAsIsEnbled
        },
        {
            "ButtonSaveAllTextAsIsEnabled"
            ,
            ButtonSaveAllTextAsIsEnabled
        },
        {
            "ButtonClearIsEnabled"
            ,
            ButtonClearIsEnabled
        },
        {
            "ButtonIDoIsEnabled"
            ,
            ButtonIDoIsEnabled
        },
        {
            "FormulaHolderIsEnabled"
            ,
            FormulaHolderIsEnabled
        }
    };

    await Shell.Current.GoToAsync
        (
            nameof(ControlPanel)
            , true
            , prams
        );
}

and then from there navigate to the AboutHelp page with the command

[RelayCommand]
public void HelpClicked()
{
    _ = Shell.Current.GoToAsync($"//{nameof(ControlPanel)}/{nameof(AboutHelp)}", true);
}

hen the Back arrow button works from the AboutHelp page back to the ControlPanel page but then there is no Back arrow button above the ControlPanel page.

My AppShell.xaml.cs looks like this:


namespace PdfCalculator;

public partial class AppShell : Shell
{
    public AppShell()
    {
        InitializeComponent();

        Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
        Routing.RegisterRoute(nameof(ControlPanel), typeof(ControlPanel));
        Routing.RegisterRoute(nameof(AboutHelp), typeof(AboutHelp));
        Routing.RegisterRoute(nameof(LineChartView), typeof(LineChartView));
    }
}

Navigate from MainPage to ControlPanel to AboutHelp

Would expect Back arrow button (that worked) on all pages.

Upvotes: 0

Views: 1103

Answers (1)

Liyun Zhang - MSFT
Liyun Zhang - MSFT

Reputation: 14244

I have create a new project to test the Shell.Current.GoToAsync($"//{nameof(ControlPanel)}/{nameof(AboutHelp)}", true); in the ControlPanel Page, but there was nothing heppened. It will not navigate from the ControlPanel Page to AboutHelp Page.

According to the official document about the Absolute routes:

the code such as await Shell.Current.GoToAsync("//animals/monkeys"); is used for navigates to the page for the monkeys route, with the route being defined on a ShellContent object. The ShellContent object that represents the monkeys route is a child of a FlyoutItem object, whose route is animals

But in your code about registering the route, the AboutHelp Page is not a child of the ControlPanel Page. So you can try to use Shell.Current.GoToAsync({nameof(AboutHelp), true) directly.

In addition, there is a bug about the navigation back button. When you register the route both in the AppShell.xaml and the AppShell.xaml.cs. Such as used both <ShellContent Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}" /> and Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));. The back button will not work since the third page in the navigation stack. You need to delete the Route="MainPage" in the <ShellContent>.

For more information, you can refer to this case about AppShell- Failed to Navigate Back.

Upvotes: 0

Related Questions