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

查看:112
本文介绍了如何从框架的历史记录中删除页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在WinRT XAML应用中操纵Frame的历史记录?

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:

  • 框架历史记录:集线器. 用户单击新建项目".
  • 框架历史记录:集线器->向导页面1. 用户单击下一步".
  • 框架历史记录:集线器->向导页面1->向导页面2.用户单击完成".
  • 框架历史记录:中心->编辑项目.
  • 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?

推荐答案

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

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. 在程序启动时,通过调用GetNavigationState保存空的导航状态.
  2. 在为您的编辑项目"页面调用导航"之前,请以空的导航状态调用SetNavigationState.

您的编辑项目"页面现在将成为堆栈中的第一页.

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

这篇关于如何从框架的历史记录中删除页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆