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

ara*_*ide 2 windows-phone-7

我正在开发一个关于wp7的应用程序.

我希望在用户退出应用程序时按下确认对话框(按后退按钮).

可能吗?

欢迎任何评论

San*_*thu 5

请在"应用程序"页面中处理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)