Removing the BackStack Entry in MetroStyle Applica

2019-08-05 06:06发布

How can I implement removing the backStack Entry in Metro style applications?

3条回答
男人必须洒脱
2楼-- · 2019-08-05 06:47

I found this answer useful:

How to clear Backstack of the frame and start afresh

Write your own NavigationService and store the navigationstate in the constructor.

string state;

public NavigationService(Frame mainFrame)
{
    state = mainFrame.GetNavigationState();

_mainFrame = mainFrame;
_mainFrame.Navigating += _mainFrame_Navigating;
}

Then implement this method on the service and call it when needed:

    public void ClearBackstack()
    {
        _mainFrame.SetNavigationState(state);
    }
查看更多
smile是对你的礼貌
3楼-- · 2019-08-05 06:48
frame.SetNavigationState("1,0");

will clear the navigation history for you.

查看更多
Emotional °昔
4楼-- · 2019-08-05 06:52

It doesn't seem to be possible. If you want to clear the back stack entirely (e.g. if you have a "home" button), you can use the code supplied in the LayoutAwarePage.cs file in the grid sample app.

if (this.Frame != null)
{
    while (this.Frame.CanGoBack) this.Frame.GoBack();
}

While this doesn't actually clear the stack, it does take you back to the program's start location and there will be no further back-direction entries in the list. If you want to back out of a dead-end page by pressing a button, you could modify this behaviour to step back a number of pages and effectively remove the back entries.

查看更多
登录 后发表回答