如何覆盖窗口返回按钮的Windows Phone 8? [英] how to override windows back button in windows phone 8 ?
问题描述
我要ovveride窗口后退按钮,当我从我的应用程序。我试过2以下方法点击,但它不是在的Windows Phone 8?
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 ?
工作方法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)
method 2 )
一)在XAML中写下这个标题
a) wrote this in xaml heading
BackKeyPress="MyBackKeyPress"
二)构造Initlize这个
b) Initlize this in constructor
BackKeyPress += OnBackKeyPress;
c)和调用此方法
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 ?
推荐答案
根据认证要求,不建议覆盖后退按钮 -
As per certification requirements it is not recommended to override the back button -
这是一个应用程序的第一个屏幕按后退按钮必须关闭
的应用程序。
Pressing the Back button from the first screen of an app must close the app.
的 http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh184840%28v=vs.105%29.aspx
您可以试试这个代码
protected override void OnBackKeyPress(CancelEventArgs e)
{
if(MessageBox.Show("Are you sure you want to exit?","Confirm Exit?",
MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
这篇关于如何覆盖窗口返回按钮的Windows Phone 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!