WinRT的框架和页面缓存:如何创建导航(新页面实例),并保持在页面实例上GoBack的()

编程入门 行业动态 更新时间:2024-10-28 04:22:21
本文介绍了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):

  • 创建于新页面实例导航()
  • 请在页面实例 GoBack的()
  • Create new page instance on Navigate()
  • 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.

  • TvShowListPage 是入门页面。点击后 TvShow 导航到 TvShowDetailsPage 。
  • 现在,在 TvShowDetailsPage 在列表中选择一个赛季,并导航到 TvShowDetailsPage 。
  • 如果导航回,页面应该留在内存中,避免重新加载页面。
  • 但是,如果用户可以追溯到 TvShowListPage 并选择另一个 TvShow 的 TvShowDetailsPage 被回收,并可能在错误的状态(例如显示投支点而不是第一个,赛季支点)
  • TvShowListPage is the entry page. After clicking on a TvShow navigate to TvShowDetailsPage.
  • Now in TvShowDetailsPage select a season in the list and navigate to the TvShowDetailsPage.
  • If navigating back, the pages should stay in memory to avoid reloading the pages.
  • 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 它提供了所有这些类可以在这里下载:github/MyToolkit/MyToolkit/wiki/Paging-Overview

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

    参考文献:

    • www.jayway/2012/05/25/clearing-the-windows-8-page-cache/:没有很好的解决办法
    • social.msdn.microsoft/Forums/en-US/winappswithcsharp/thread/88e6d1b3-1fa6-4ab4-a816-e77c86ef236f/:一个自己的框架类的实现是无解的,因为它不与 SuspensionManager 工作
    • www.jayway/2012/05/25/clearing-the-windows-8-page-cache/: No good solution
    • social.msdn.microsoft/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...

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

    The solution can be downloaded here: github/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的()

    本文发布于:2023-11-03 06:20:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1554431.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:实例   页面   缓存   框架   新页面

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!