如何从Frame'的历史中删除页面?[英] How can I remove pages from a Frame's history?

本文是小编为大家收集整理的关于如何从Frame'的历史中删除页面?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何在Winrt XAML应用中操纵框架的历史?

用户将在我的集线器页面上启动,他们可以在其中选择一个现有的项目以进入其编辑屏幕,或者可以选择"新项目". "新项目"将带它们穿过一个简短的向导,然后将它们带到"编辑项目"屏幕.

对向导页面只是我在框架中导航到的页面是有意义的.这样,如果用户改变主意,就可以退出向导. (这只会是两个页面,因此"返回"可以代替"取消".)但是,一旦向导完成并进行了更改,就不再有任何理由让这些向导页面进入历史;如果用户从"编辑项目"页面中单击返回,我希望他们直接回到集线器.

要说明,我希望流程看起来像这样:

  • 框架历史:集线器. 用户单击"新项目".
  • 框架历史记录:集线器 - >向导页面1.用户单击"下一步".
  • 框架历史记录:集线器 - >向导页面1->向导页面2.用户单击"完成".
  • 框架历史记录:集线器 - >编辑项目.

frame 不似乎沿着"从历史上删除"的线有任何方法.文档确实有暗示可能有某种方法可以覆盖历史记录,因为推荐答案

您可以通过在框架上调用setNavigationState(String navigationState)从历史记录中删除页面.不幸的是,序列化导航态的格式是"仅供内部使用",因此仅更改字符串可能会在以后的版本中破坏您的代码.

我只能想到 完全清晰 导航堆栈的未来证明方法:

  1. 在程序启动时,通过调用getNavigationState来保存空导航状态.
  2. 在致电导航以获取编辑项目页面之前,请使用空导航状态调用SetNavigationState.

您的编辑项目页面现在将是堆栈上的第一页.

其他推荐答案

从Windows 8.1开始,您可以访问帧的背面属性.您可以轻松删除一些内容或清除整个后堆栈.

这是我正在使用清晰的后堆栈:

var rootFrame   = (Window.Current.Content as Frame);
rootFrame.Navigate(typeof(MyPage));
rootFrame.BackStack.Clear();

其他推荐答案

它对我的解决方案:

while (ContentFrame.BackStack.Count > 1)
            {
              ContentFrame.BackStack.Remove(ContentFrame.BackStack.ElementAt(ContentFrame.BackStack.Count-1));

            }

本文地址:https://www.itbaoku.cn/post/2091153.html

问题描述

How can I manipulate a Frame's history in a WinRT XAML app?

The user will start on my hub page, where they can select an existing project to go to its edit screen, or they can select "new project". "New project" will take them through a short wizard, then take them to the "edit project" screen.

It makes sense for the wizard pages to just be pages that I navigate to in the frame; that way the user can back out of the wizard if they change their mind. (It'll only be two pages, so "back" can take the place of "cancel".) But once the wizard is done and the changes are committed, there's no longer any reason for those wizard pages to be in the history; if the user clicks Back from the "edit project" page, I want them to go right back to the hub.

To illustrate, I want the flow to look something like this:

  • Frame history: Hub. User clicks "New Project".
  • Frame history: Hub -> Wizard Page 1. User clicks "Next".
  • Frame history: Hub -> Wizard Page 1 -> Wizard Page 2. User clicks "Finish".
  • Frame history: Hub -> Edit Project.

Frame doesn't seem to have any methods along the lines of "remove from history". The docs do have hints that there might be some way to override the history, because the docs for GoBack say "Navigates to the most recent item in back navigation history, if a Frame manages its own navigation history" (emphasis mine), but that's all it has to say on the topic -- there's no mention of how someone else can manage history for it. So I don't know whether that's useful or not.

How can I remove my wizard pages from my Frame's history once the user completes the wizard?

推荐答案

You can remove pages from the history by calling SetNavigationState(string navigationState) on the frame. Unfortunately the format of the serialized navigationState is "for internal use only", so just changing the string might break your code in future versions.

I only can think of a future proof method to completely clear the navigation stack:

  1. At program startup save the empty navigation state by calling GetNavigationState.
  2. BEFORE calling Navigate for your Edit Project page, call SetNavigationState with the empty navigation state.

Your Edit Project page will now be the first page on the stack.

其他推荐答案

Starting with Windows 8.1, you have access to the BackStack property of a Frame. You can easily remove some content or clear the whole back stack.

Here is what I'm using the clear the back stack :

var rootFrame   = (Window.Current.Content as Frame);
rootFrame.Navigate(typeof(MyPage));
rootFrame.BackStack.Clear();

其他推荐答案

its a solution for me :

while (ContentFrame.BackStack.Count > 1)
            {
              ContentFrame.BackStack.Remove(ContentFrame.BackStack.ElementAt(ContentFrame.BackStack.Count-1));

            }