【问题标题】:How does windows 8 manage stack of Pages in Frame?Windows 8 如何管理 Frame 中的 Pages 堆栈?
【发布时间】:2012-07-04 10:10:47
【问题描述】:

Windows 8 如何在一个框架中管理一堆页面?

我怎样才能以编程方式清除整个堆栈,因为我需要“弹出”堆栈中的所有页面并返回到我开始的第一页(比如说登录页面)?

【问题讨论】:

    标签: .net windows-8 windows-runtime


    【解决方案1】:

    看看the Frame class的方法

    this article(关于导航的必读):

    private void ResetPageCache()
    {
        var cacheSize = ((Frame) Parent).CacheSize;
        ((Frame) Parent).CacheSize = 0;
        ((Frame) Parent).CacheSize = cacheSize;
    }
    

    【讨论】:

    • 我明白了...仍在寻找更好的解决方案..!!
    • Erno 提到的那篇文章也谈到了 Page 类的 NavigationCacheMode (msdn.microsoft.com/en-us/library/windows/apps/…) 属性。有了它 - 您可以逐页控制页面的缓存方式。
    • @Erno 我尝试了那篇文章中的代码,但我再次想知道“为什么我不能清除我的堆栈”,因为我可以看到“Backstackdepth”属性不断增加..isnt缓存与“Backstack”不同的现象??
    【解决方案2】:

    在 Common/LayoutAwarePage.cs 中有以下 GoHome() 函数(除了与标准后退按钮上的 Click-event 一起使用的 GoBack() 函数):

        // Use the navigation frame to return to the topmost page
        if (this.Frame != null)
        {
            while (this.Frame.CanGoBack) this.Frame.GoBack();
        }
    

    【讨论】:

      【解决方案3】:

      尝试实现您自己的 Frame 类,类似于以下内容:

      http://blogs.microsoft.co.il/blogs/eshaham/archive/2012/04/30/fixing-frame-navigation-in-metro-style-apps.aspx

      然后你可以编写一个 RemoveLastEntry 方法,它基本上是这样做的:

      void RemoveLastEntry()
      {
          if (_navigationStack.Count > 0)
          {
              _navigationStack.Pop();
          }
      }
      

      并调用此方法一定次数。

      或者您可以调用 GoHome 方法将您带回第一个屏幕(这将清除除第一个项目之外的整个堆栈)。

      我希望这会带你走向正确的方向!

      【讨论】:

        【解决方案4】:

        最好的解决办法是

        while (this.Frame.CanGoBack)
        {
            this.Frame.GoBack();
        }
        

        【讨论】:

          猜你喜欢
          • 2011-09-16
          • 1970-01-01
          • 1970-01-01
          • 2013-01-30
          • 1970-01-01
          • 2020-11-23
          • 1970-01-01
          • 2015-09-28
          • 1970-01-01
          相关资源
          最近更新 更多