當我從我的應用程序點擊時,我需要ovveride窗口後退按鈕。我嘗試了下面的2個方法,但它不能在Windows Phone 8中工作?如何在windows phone 8中覆蓋windows back按鈕?
方法1)
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
var result = MessageBox.Show("Do you want to exit?", "Attention!",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
// base.OnBackKeyPress(e);
return;
}
e.Cancel = true;
}
方法2)
一)在XAML寫這個標題
BackKeyPress="MyBackKeyPress"
b)以構造
BackKeyPress += OnBackKeyPress;
c)中Initlize此並調用這個方法
private void MyBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; //tell system you have handled it
//you c
}
這兩種方法都不起作用。當我點擊後退按鈕時,應用程序被摧毀,無法獲得後退控件。任何幫助?
是的,我把代碼不在起始頁面。這不起作用。我正在使用模擬器進行測試。 – user1703145
你有沒有例外?崩潰? – Anuraj
應用正在退出,沒有發生任何異常,也沒有崩潰。 – user1703145