1

我有一个名为的页面Page1.xaml,可以从Page2.xaml和访问和访问Page3.xaml。我不想从 to 转回来Page1Page3只是 to Page2

现在,当我这样做时,会发生异常:

if (this.NavigationService.BackStack.Any())
{

}

这是:Attempted to read or write protected memory.

有人可以告诉我如何简单地按照我上面所说的方式为 WP7 和 WP8 工作(msdn 文档在这里和那里讨论,所以我错过了重点。)

更新:当我使用NavigationService.CanGoBack相同的错误时:Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

4

1 回答 1

1

如果您只想知道 BackStack 上是否有项目,那么您应该使用NavigationService的CanGoBack属性。

if(NavigationService.CanGoBack)
{
    // logic
}

如果要删除 BackStack 的所有条目,请使用RemoveBackEntry方法。

while (NavigationService.CanGoBack) 
{
    NavigationService.RemoveBackEntry();
}
于 2013-07-06T05:14:10.530 回答