C# WPF Disable the exit/close button

c#, wpf

Solution

in wpf this event called Closing :

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

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

Problem

Is it possible to disable the close button in a WPF form? How can I disable the close button? I have been searching around and found the solution below. But that works only in Windows Form! ``` private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; } ```

Original source

Related problems