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