wpf - 取消在WPF中关闭窗口

标签 wpf

我知道这个问题与this one非常相似,但是我认为以下代码可以取消关机请求,但是不是吗?谁能解释为什么?

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

最佳答案

MSDN:

Important: When Shutdown is called, the application will shut down irrespective of whether the Closing event of any open windows is canceled.

关于wpf - 取消在WPF中关闭窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4614477/

相关文章:

wpf - TreeView SelectedItem 返回类型

c# - 在 XAML 中设置 WPF OxyPlot PlotViews 的样式

c# - 在 MVVM 中数据绑定(bind) ObservableCollection<T>

c# - ListView : Enable text trimming instead of HorisontalScrollBar

.net - 运行简单的计时器

wpf - 在 Window.Resources 中使用通用类型

wpf - 关于 WPF 对接库的建议

c# - 将应用程序资源中的 DependancyProperty 绑定(bind)到控件 DependancyProperty(正在使用该资源)

c# - 将不同的集合绑定(bind)到数据网格

c# - 条件键绑定(bind)