且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

退出应用程序时提示确认对话框

更新时间:2022-05-28 01:18:11

请处理 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;
            }

        }