控制按“后退按钮”并禁用使用确认对话框关闭应用程序 - wp7

发布于 2024-12-09 14:23:01 字数 129 浏览 6 评论 0原文

我需要显示一个简单的对话框,其中包含以下问题:“您想退出应用程序吗?”是还是不是。 当用户按下设备的后退按钮时,将显示此对话框。

我知道如何显示此对话框,但我不知道如何禁用后退操作:关闭应用程序。

它总是关闭的。

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.

It's always closed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛上了 2024-12-16 14:23:01

如果我理解正确的话,当用户单击应用程序主页上的后退按钮时,您希望显示一个确认对话框,询问他们是否真的要退出。如果用户选择“是”,应用程序将退出,否则您将取消后退导航。为此,请在 MainPage 类构造函数中连接一个事件处理程序

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文