Possible Duplicate:
How to distinguish ‘Window close button clicked (X)’ vs. window.Close() in closing handler
In WPF, here are different ways to close a Window
:
1) Window.Close()
2) Select 'Close' from Window system menu (top left)
3) Click 'X' button on Window title bar (top right)
4) Keyboard shortcut: Alt+F4
All of these actions trigger WPF event Window.Closing
How do I distinguish between these two types of actions?
In Excel/VBA this is possible: VBA.VbQueryClose.vbFormCode
vs VBA.VbQueryClose.vbFormControlMenu
.
This related question/answer says the system menu actions will generate Windows event WM_CLOSE
. Perhaps there is a way to see the underlying Windows event from WPF.