我知道这个问题与this one非常相似,但是我认为以下代码可以取消关机请求,但是不是吗?谁能解释为什么?
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
}
}
最佳答案
从MSDN:
Important: When Shutdown is called, the application will shut down irrespective of whether the Closing event of any open windows is canceled.
关于wpf - 取消在WPF中关闭窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4614477/