如何覆盖 Windows Phone 8 中的 Windows 后退按钮? [英] how to override windows back button in windows phone 8 ?

查看:15
本文介绍了如何覆盖 Windows Phone 8 中的 Windows 后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从我的应用程序中单击时,我需要覆盖 Windows 后退按钮.我尝试了下面的 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;
    }

方法二)

a) 在 xaml 标题中写了这个

a) wrote this in xaml heading

BackKeyPress="MyBackKeyPress"

b) 在构造函数中初始化它

b) Initlize this in constructor

 BackKeyPress += OnBackKeyPress;

c) 并调用此方法

   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 中的 Windows 后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆