WinRT的框架和页面缓存:如何创建导航(新页面实例),并保持在页面实例上GoBack的() [英] WinRT Frame and Page caching: How to create new page instance on Navigate() and keep the page instance on GoBack()

查看:205
本文介绍了WinRT的框架和页面缓存:如何创建导航(新页面实例),并保持在页面实例上GoBack的()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Windows 8地铁风格的应用程序用C#。我的问题是框架控制:如果我使用它,而 NavigationCacheMode =必需,每个用户可以追溯到时候,页是不保留在内存中,将被重新创建。如果设置了 NavigationCacheMode 必需已启用,回去正常工作(没有新的页面对象)的,但如果我浏览到另一页从同一个类型,previous页面对象被回收再利用(没有新的页面实例)。

I'm trying to create a Windows 8 Metro styled application with C#. My problem is the Frame control: If I use it without NavigationCacheMode = Required, every time the user goes back, the page is not kept in memory and will be recreated. If I set NavigationCacheMode to Required or Enabled, going back works correctly (no new page object) but if I navigate to another page from the same type, the previous page object is recycled and reused (no new page instance).

期望的行为:

有没有办法有一个与原始的框架控件(如Windows Phone中)以下行为:

Is there a way to have the following behaviour with the original Frame control (like in Windows Phone):

  1. 创建于新页面实例导航()
  2. 请在页面实例 GoBack的()
  1. Create new page instance on Navigate()
  2. Keep the page instance on GoBack()

我知道的唯一解决方案是创建一个自己的框架控制,但是这会导致其他问题(如:缺少 SetNavigationState()法,等...)

The only solution I know is to create an own Frame control but this leads to other problems (e.g.: missing SetNavigationState() method, etc...)

示例场景:

有三页简单的应用例如: TvShowListPage TvShowDetailsPage SeasonDetailsPage

Simple application example with three pages: TvShowListPage, TvShowDetailsPage, SeasonDetailsPage.

  1. TvShowListPage 是入门页面。点击后 TvShow 导航到 TvShowDetailsPage
  2. 现在,在 TvShowDetailsPage 在列表中选择一个赛季,并导航到 TvShowDetailsPage
  3. 如果导航回,页面应该留在内存中,避免重新加载页面。
  4. 但是,如果用户可以追溯到 TvShowListPage 并选择另一个 TvShow TvShowDetailsPage 被回收,并可能在错误的状态(例如显示投支点而不是第一个,赛季支点)
  1. TvShowListPage is the entry page. After clicking on a TvShow navigate to TvShowDetailsPage.
  2. Now in TvShowDetailsPage select a season in the list and navigate to the TvShowDetailsPage.
  3. If navigating back, the pages should stay in memory to avoid reloading the pages.
  4. But if the users goes back to TvShowListPage and selects another TvShow the TvShowDetailsPage gets recycled and is maybe in the wrong state (eg showing the cast pivot instead of the first, seasons pivot)

我在寻找默认的Windows Phone 7的行为:创建导航页面上堆了新的一页,回去从栈中删除顶部页面,并显示堆栈中的previous页(存储在内存中)。

I'm looking for the default Windows Phone 7 behavior: Navigating creates a new page on the page stack, going back removes the top page from the stack and displays the previous page from the stack (stored in the memory).

解决方法:

由于没有解决这个问题,我不得不重新实现所有分页相关的类:页,框架,SuspensionManager,等等...

Because there was no solution to this problem, I had to reimplement all paging relevant classes: Page, Frame, SuspensionManager, etc...

库MyToolkit 它提供了所有这些类可以在这里下载:<一href="https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview">https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview

The library MyToolkit which provides all these classes can be downloaded here: https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview

参考文献:

  • <一个href="http://www.jayway.com/2012/05/25/clearing-the-windows-8-page-cache/">http://www.jayway.com/2012/05/25/clearing-the-windows-8-page-cache/:没有很好的解决办法
  • <一个href="http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/88e6d1b3-1fa6-4ab4-a816-e77c86ef236f/">http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/88e6d1b3-1fa6-4ab4-a816-e77c86ef236f/:一个自己的框架类的实现是无解的,因为它不与 SuspensionManager 工作
  • http://www.jayway.com/2012/05/25/clearing-the-windows-8-page-cache/: No good solution
  • http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/88e6d1b3-1fa6-4ab4-a816-e77c86ef236f/: Implementing of an own Frame class is no solution as it doesn't work with SuspensionManager

推荐答案

由于没有解决这个问题,我不得不重新实现所有分页相关的类:页,框架,SuspensionManager,等等...

Because there was no solution to this problem, I had to reimplement all paging relevant classes: Page, Frame, SuspensionManager, etc...

该解决方案可以在这里下载: https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview

The solution can be downloaded here: https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview

更新:

页面类现在还提供了 OnNavigatingFromAsync 方式来显示例如异步弹出,如果需要取消导航...

The page class now also provides the OnNavigatingFromAsync method to show for example an async popup and cancel navigation if required...

这篇关于WinRT的框架和页面缓存:如何创建导航(新页面实例),并保持在页面实例上GoBack的()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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