Removing the BackStack Entry in MetroStyle Application

三世轮回 提交于 2019-12-13 00:29:16

问题


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


回答1:


frame.SetNavigationState("1,0");

will clear the navigation history for you.




回答2:


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);
    }



回答3:


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.



来源:https://stackoverflow.com/questions/13009475/removing-the-backstack-entry-in-metrostyle-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!