控制preSS"后退按钮"并使用确认对话框禁用关闭应用程序 - WP7 [英] Control press "back button" and disable close the application using a dialog for confirm - wp7

查看:162
本文介绍了控制preSS"后退按钮"并使用确认对话框禁用关闭应用程序 - WP7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要证明的问题,一个简单的对话框:'吗?你想退出应用程序是或否。
当用户presses设备的后退按钮会显示该对话框。

I need show a simple dialog with the question : 'Do you want to exit the application?' YES or NO. This dialog will be shown when the user presses the back button of the device.

我知道我可以显示此对话框,但我不知道如何禁用回动作:关闭应用程序。

I know how I can show this dialog , but I don't know how to disable the back action: close app.

它总是关闭。

推荐答案

如果我理解正确的话,你希望当用户点击您的应用程序的主网页上的后退按钮问问自己是否真的想显示一个确认对话框退出。如果用户选择的是应用程序退出,否则取消后退导航。要做到这一点,在的MainPage 的类的构造函数挂钩的事件处理程序

If I understand you correctly, you want to display a confirmation dialog when the user clicks the back button on the main page of your app to ask whether they really want to exit. If the user selects Yes the app exits, otherwise you cancel the back navigation. To do this, in the MainPage class constructor hook up an event handler

MainPage()
{
  BackKeyPress += OnBackKeyPressed;
}

void OnBackKeyPressed( object sender, CancelEventArgs e )
{
  var result = MessageBox.Show( "Do you want to exit?", "Attention!", 
                                MessageBoxButton.OKCancel );

  if( result == MessageBoxResult.OK ) {
    // Do not cancel navigation
    return;
  }
  e.Cancel = true;
}

这篇关于控制preSS"后退按钮"并使用确认对话框禁用关闭应用程序 - WP7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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