gpt4 book ai didi

wpf - 取消在WPF中关闭窗口

转载 作者:行者123 更新时间:2023-12-03 12:13:49 26 4
gpt4 key购买 nike

我知道这个问题与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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com