2011-01-06 112 views
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; 
     }   
    } 
} 

回答

25

MSDN

重要:当关闭被调用时, 应用程序将不考虑任何打开的窗口关闭 事件是否取消关闭 。