How to override default window close operation?

后端 未结 3 1448
南方客
南方客 2020-12-10 01:58

In WPF I want to change default close behaviour of some window, so that when user clics red close button the window does not close, it merely hides (and call some method as

3条回答
  •  余生分开走
    2020-12-10 02:12

    This page should help.

    Closing can be handled to detect when a window is being closed (for example, when Close is called). Furthermore, Closing can be used to prevent a window from closing. To prevent a window from closing, you can set the Cancel property of the CancelEventArgs argument to true.

    And

    If you want to show and hide a window multiple times during the lifetime of an application, and you don't want to reinstantiate the window each time you show it, you can handle the Closing event, cancel it, and call the Hide method. Then, you can call Show on the same instance to reopen it.

提交回复
热议问题