20
我知道这个问题非常类似于this one,但我会想到下面的代码会取消关闭请求,但它不会?谁能解释为什么?取消WPF中的窗口关闭
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;
}
}
}