退出应用程序时提示确认对话框 [英] prompt confirmation dialog when exit app

查看:33
本文介绍了退出应用程序时提示确认对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 wp7 上开发一个应用.

I am working on an app on wp7.

我希望在用户退出应用程序时提示确认对话框(按返回按​​钮).

I hope to prompt a confirmation dialog when user exit app (press back button).

有可能吗?

欢迎任何评论

推荐答案

请处理 Application 页面中的 BackKeyPress 按钮来处理后退键按下.

Please handle the BackKeyPress button in the Application page to handle the back key press.

在 Page.xaml 文件中的元素中添加此代码

In Page.xaml file in the element add this code

BackKeyPress="PhoneApplicationPage_BackKeyPress"

它应该看起来像

<phone:PhoneApplicationPage BackKeyPress="PhoneApplicationPage_BackKeyPress"
..//other attributes .. >

在事件处理程序中编写如下代码

in event handler you write the code as follows

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;
            }

        }

这篇关于退出应用程序时提示确认对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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