I am aware that this question is very similar to this one, but I would have thought the following code would have canceled the shutdown request, but it doesn't? Can anyone explain why?
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.ComponentMode开发者_开发问答l.CancelEventArgs e)
        {
            e.Cancel = true;
        }        
    }
}
From MSDN:
Important: When Shutdown is called, the application will shut down irrespective of whether the Closing event of any open windows is canceled.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论