How does Windows 8 manage a stack of Pages in a Frame?
And how can I clear the whole stack programmatically, as in I need to 'pop' all pages in a stack and return to first page where I started from (let's say Login Page)?
How does Windows 8 manage a stack of Pages in a Frame?
And how can I clear the whole stack programmatically, as in I need to 'pop' all pages in a stack and return to first page where I started from (let's say Login Page)?
在 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();
}