2013-07-06 121 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(); 
}