简体   繁体   中英

Navigation Issue in Xamarin Forms

I need to route pages A -> B -> C -> D, once I got into D, I need to use the navigation button back to page D -> A. I am trying to implement this scenario IOS and Android in Xamarin Forms.

Please help

Your case use the Navigation.PopToRootAsync ();

Navigation.PopToRootAsync (); This method pops all but the RootPage off the navigation stack, therefore making the root page of the application the active page.

Navigation.PopAsync (); This causes the Page2Xaml instance to be removed from the navigation stack, with the new topmost page becoming the active page.

The following doc explains well about Xamarin.Forms Navigation. https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical

Inside the "D" page override the "OnBackButtonPressed" and inside the function iterate trough the pages you no longer need and remove them one by one.

Pseudo code:

    protected override bool OnBackButtonPressed()
    {
        foreach (var page in Navigation.NavigationStack)
        {

            //find the pages you want to remove
            Navigation.RemovePage(PageYouFound);
        }
        //Set new page
        return base.OnBackButtonPressed();

    }

You can oveeride OnBackButtonPressed Event and use Navigation.PopToRootAsync

protected override bool OnBackButtonPressed()
    {
        Navigation.PopToRootAsync();
        return base.OnBackButtonPressed();

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM