【发布时间】:2014-05-06 04:57:50
【问题描述】:
当我从我的应用程序中单击时,我需要覆盖 Windows 后退按钮。我尝试了下面的 2 种方法,但它在 windows phone 8 中不起作用?
方法 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)
a) 在 xaml 标题中写了这个
BackKeyPress="MyBackKeyPress"
b) 在构造函数中初始化 this
BackKeyPress += OnBackKeyPress;
c) 并调用此方法
private void MyBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; //tell system you have handled it
//you c
}
这两种方法都不起作用。当我单击后退按钮时,应用程序被破坏并且无法控制后退按钮。有什么帮助吗?
【问题讨论】:
标签: c# windows-phone-7 windows-phone-8