title: Cancel a window closing in WPF
body: <p>I am aware that this question is very similar to <a href="https://stackoverflow.com/questions/3101801/cancel-wpf-application-current-shutdown">this one</a>, but I would have thought the following code would have canceled the shutdown request, but it doesn't? Can anyone explain why?</p>
  
  <pre><code>namespace WpfApplication1
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      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;
          }        
      }
  }
  </code></pre>