在桌面应用程序中通过单击“X”按钮或按 ESC 键关闭 WPF 窗口时如何请求确认?
我想用最少的代码来实现它。
类似的问题是 here但是在 MVVM Light 上,代码太多了。
最佳答案
利用 OnClosing
虚方法:
protected override void OnClosing(CancelEventArgs e)
{
// show the message box here and collect the result
// if you want to stop it, set e.Cancel = true
e.Cancel = true;
}
该内部代码可能如下所示:
var result = MessageBox.Show(...);
if (result == DialogResult.{SomeEnumVal}) { e.Cancel = true; }
关于c# - 使用 'X' 按钮或 ESC 键关闭 WPF 窗口时的确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19589462/