How to catch the event of the window close button(red X button on window right top corner) in wpf form?

前端 未结 6 1302
醉酒成梦
醉酒成梦 2021-01-03 18:22

How can I catch the event of the window close button(red X button on window right top corner) in a WPF form? We have got the closing event, window unloaded event also, but w

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 19:00

    Use the Closing event in the Window, you can handle it like this to prevent it from closing:

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

提交回复
热议问题