Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to Navigate in Shell without pushing in the existing Navigation Stack

begbeg Member ✭✭

In our companys app, we have a logo on the top of the ShellPage. When you press on the logo, you should be navigated back to the Homepage.
This logic is bound to an eventhandler in the codebehind of the AppShell.
But when i navigate via the GotoAsync method, the Homepage is pushed to the Navigation stack.
I want this logic to behave exactly like pressing on the Page in the Flyout, so there is no Navigationstack with multiple pages.

How can i realise that?

Best Answer

  • begbeg Member ✭✭
    edited August 2019 Accepted Answer

    I found the solution
    i had to define a Route for the ShellContent and then add the Route as parameter for the GotoAsync method

    ShellPage.xaml

    `<FlyoutItem
            Title="Startseite">
            <ShellContent Route="Home"
                Title="Startseite"
                Style="{StaticResource DomesticShell}"
                ContentTemplate="{DataTemplate homePage:HomePage}" />
    
        </FlyoutItem>`
    

    ShellPage.xaml.cs
    GoToAsync("//Home")



    before i was referring to the registered route in the codebehind. it was defined like this:

    ShellPage.xaml.cs
    Routing.RegisterRoute("HomePage", typeof(HomePage.Views.HomePage));
    [...]
    GoToAsync("HomePage");

Answers

  • Jack_HuaJack_Hua Member ✭✭✭
    edited August 2019

    No matter which page you are in, you want to go to the homePagewithout pushing in the existing Navigation Stack?

  • begbeg Member ✭✭
  • begbeg Member ✭✭
    edited August 2019 Accepted Answer

    I found the solution
    i had to define a Route for the ShellContent and then add the Route as parameter for the GotoAsync method

    ShellPage.xaml

    `<FlyoutItem
            Title="Startseite">
            <ShellContent Route="Home"
                Title="Startseite"
                Style="{StaticResource DomesticShell}"
                ContentTemplate="{DataTemplate homePage:HomePage}" />
    
        </FlyoutItem>`
    

    ShellPage.xaml.cs
    GoToAsync("//Home")



    before i was referring to the registered route in the codebehind. it was defined like this:

    ShellPage.xaml.cs
    Routing.RegisterRoute("HomePage", typeof(HomePage.Views.HomePage));
    [...]
    GoToAsync("HomePage");

  • AdamMizam1996AdamMizam1996 Member ✭✭

    Sorry i did not quite understand the answer, maybe can explain more?... sorry for disturb i'm newbie in xamarin.form

Sign In or Register to comment.