2013-07-06 124 views
1

我有一个名为Page1.xaml的页面,可以访问并访问Page2.xamlPage3.xaml。 我不想回头从Page1Page3,只是到Page2访问BackStack时访问冲突异常

现在我做到这一点时发生异常:

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.

回答

1

如果你只是想知道是否有在堆栈中的项目,那么你应该使用NavigationServiceCanGoBack财产。

if(NavigationService.CanGoBack) 
{ 
    // logic 
} 

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

while (NavigationService.CanGoBack) 
{ 
    NavigationService.RemoveBackEntry(); 
}