How to go back multiple Pages?

Tags: c# wpf xaml uwp
By : vrwim
Source: Stackoverflow.com
Question!

In my Universal app, I want to use a Frame to navigate through my app. I also have a breadcrumb, as per the designs. Now I don't really know how to handle things when the user wants to go back multiple pages.

My breadcrumb items are simple strings that I display using a XAML ListView. I find the index of the breadcrumb the user clicked on and I try to go back so many times.

I tried using a for loop:

private void Breadcrumb_Item_Tapped(object sender, TappedRoutedEventArgs e)
{
    var breadcrumb = ((sender as Grid).DataContext as string);

    for(int i = 1; i < Breadcrumbs.Count - Breadcrumbs.indexOf(breadcrumb); i++)
    {
        frame.GoBack();
    }
}

But the frame.GoBack() doesn't always work, I'm guessing because it is going too fast after the GoBack() call before. I don't want to use a sleep method, because it should be instant.

What can I do to go back multiple pages?

By : vrwim


Answers

I would suggest using frame.BackStack.RemoveAt(frame.BackStackDepth-1)

This way you will remove the entries from the stack without actually navigating. Use a loop to decide when you should stop removing and then execute a final frame.GoBack()

By : Corcus


This video can help you solving your question :)
By: admin