【发布时间】:2012-07-04 10:10:47
【问题描述】:
Windows 8 如何在一个框架中管理一堆页面?
我怎样才能以编程方式清除整个堆栈,因为我需要“弹出”堆栈中的所有页面并返回到我开始的第一页(比如说登录页面)?
【问题讨论】:
标签: .net windows-8 windows-runtime
Windows 8 如何在一个框架中管理一堆页面?
我怎样才能以编程方式清除整个堆栈,因为我需要“弹出”堆栈中的所有页面并返回到我开始的第一页(比如说登录页面)?
【问题讨论】:
标签: .net windows-8 windows-runtime
看看the Frame class的方法
在this article(关于导航的必读):
private void ResetPageCache()
{
var cacheSize = ((Frame) Parent).CacheSize;
((Frame) Parent).CacheSize = 0;
((Frame) Parent).CacheSize = cacheSize;
}
【讨论】:
在 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();
}
【讨论】:
尝试实现您自己的 Frame 类,类似于以下内容:
然后你可以编写一个 RemoveLastEntry 方法,它基本上是这样做的:
void RemoveLastEntry()
{
if (_navigationStack.Count > 0)
{
_navigationStack.Pop();
}
}
并调用此方法一定次数。
或者您可以调用 GoHome 方法将您带回第一个屏幕(这将清除除第一个项目之外的整个堆栈)。
我希望这会带你走向正确的方向!
【讨论】:
最好的解决办法是
while (this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
【讨论】: