请在"应用程序"页面中处理BackKeyPress按钮以处理后退键.
在元素的Page.xaml文件中添加此代码
BackKeyPress="PhoneApplicationPage_BackKeyPress"
Run Code Online (Sandbox Code Playgroud)
它应该看起来像
<phone:PhoneApplicationPage BackKeyPress="PhoneApplicationPage_BackKeyPress"
..//other attributes .. >
Run Code Online (Sandbox Code Playgroud)
在事件处理程序中,您按如下方式编写代码
private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult mb = MessageBox.Show("You want exit the page", "Alert", MessageBoxButton.OKCancel);
if( mb != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
Run Code Online (Sandbox Code Playgroud)