如何捕捉窗口关闭按钮(红色的X按钮在窗口右上角)在WPF形式的活动? [英] How to catch the event of the window close button(red X button on window right top corner) in wpf form?

查看:768
本文介绍了如何捕捉窗口关闭按钮(红色的X按钮在窗口右上角)在WPF形式的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何捕捉窗口关闭按钮(红色的X按钮在窗口右上角)在WPF形式的活动?我们已经得到了关闭事件,窗口卸载事件也有,但是我们要显示一个弹出,如果他点击了WPF窗体的关闭按钮。

How to catch the event of the window close button(red X button on window right top corner) in wpf form ? We have got the closing event, window unloaded event also, but we want to show a pop up if he clicks the close button of the wpf form.

请帮助。

推荐答案

使用在窗口关闭事件,你可以处理它像这种以防止它结束:

Use the Closing event in the Window, you can handle it like this to prevent it from closing:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
}

这篇关于如何捕捉窗口关闭按钮(红色的X按钮在窗口右上角)在WPF形式的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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