Advertise with us

Disable the exit/close button in C# WPF.

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;
}
Last updated:7/19/2013 6:24:12 AM

1 Answers

Vijay Shukla
Vijay Shukla

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

Last updated:7/19/2013 6:24:12 AM

Answer