C# WPF 禁用退出/关闭按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16132872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:38:34  来源:igfitidea点击:

C# WPF Disable the exit/close button

c#wpf

提问by EM10

Is it possible to disable the close button in a WPF form? How can I disable the close button?

是否可以禁用 WPF 表单中的关闭按钮?如何禁用关闭按钮?

I have been searching around and found the solution below. But that works only in Windows Form!

我一直在四处寻找,并在下面找到了解决方案。但这仅适用于 Windows 窗体!

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
      e.Cancel = true;
}

回答by user1064519

in wpf this event called Closing :

在 wpf 中,此事件称为 Closing :

public Window4()
    {
        InitializeComponent();
        this.Closing += new System.ComponentModel.CancelEventHandler(Window4_Closing);
    }

    void Window4_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
    }

回答by David

You need to implement a windows hook to accomplish that. See this MSDN postfor details.

您需要实现一个 windows 钩子来实现这一点。有关详细信息,请参阅此 MSDN 帖子