Reputation: 169
How do I remove a page from the Navigation History?
I go forward like this:
this.Frame.Navigate(typeof(...));
But what I want is
A -> B -> C -> D -> E
Back?
E -> A
So I want to delete the Backward Navigation Stack. NavigationService is not available in Windows 8 as far as I know. And I don't find any useful function in the page class:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.page
Upvotes: 3
Views: 2503
Reputation: 450
On UWP, Frame.BackStack.Clear()
works fine (since it's IList<PageStackEntry>
).
Also, you may use other IList
methods (such as RemoveAt
) to accomplish your task.
Upvotes: 0
Reputation: 39988
I had same issue and I done this using the below code
while (Frame.BackStackDepth > 0)
{
if (Frame.CanGoBack)
{
Frame.GoBack();
}
}
Frame.CacheSize = 0;
Frame.Navigate(typeof(LoginScreen));
Upvotes: 0
Reputation: 69372
One way is to use Frame.SetNavigationState. When you're on page A
, store Frame.GetNavigationState in a static variable which is accessible anywhere in the app.
MyClass.PageANavigationState = Frame.GetNavigationState();
When you're on E
(or whichever page), and you want to clear the navigation stack up to A
, use
Frame.SetNavigationState[MyClass.PageANavigationState];
Upvotes: 1