I need to ovveride the windows back button when i am clicking from my application .I tried 2 method below but it is not working in windows phone 8 ?
methods 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;
}
method 2 )
a) wrote this in xaml heading
BackKeyPress="MyBackKeyPress"
b) Initlize this in constructor
BackKeyPress += OnBackKeyPress;
c) and call this method
private void MyBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; //tell system you have handled it
//you c
}
the two of the methods are not working . when i was clicked the back button the app destroyed and unable to get the control of backbutton . Any help ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…