2
我已經重寫了這個方法:如何從當前頁面以外的背面堆棧中刪除所有歷史記錄?
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
IAsyncResult guide = Guide.BeginShowMessageBox(
"Alert", "Do you want to go to the Menu Page?",
new string[] { "YES", "NO" }, 0,
MessageBoxIcon.Alert, null, null);
int result = (int)Guide.EndShowMessageBox(guide);
if (result == 0) // YES
{
NavigationService.Navigate(new Uri("/MenuPage.xaml", UriKind.RelativeOrAbsolute));
}
else // NO
{
}
}
現在,當我按「無」,它仍然使我回到前一頁,我只是想通過它僅僅停留在當前頁面上覆蓋此功能,無需重新啓動頁面。我可以嗎?
你在你的代碼的路徑是在做什麼,可能無法很好地工作。通過導航到MenuPage,您可能會在導航堆棧中創建一個錯誤的導航路徑。嘗試先調用NavigationService.RemoveBackEntry(僅限7.1)或NavigationService.GoBack()幾次。在Channel 9上觀看此視頻以獲取解釋:http://channel9.msdn.com/Series/Mango-Jump-Start/Mango-Jump-Start-03-Silverlight-on-Windows-PhoneAdvanced – 2012-03-09 10:03:15