Is there an event that is fired when the user presses the close button?
This is because the Window Closing event is fired both when one closes the window manually (with the Close method) and also when the user presses the [X] button…but I somehow need to know only when the user presses the [X] button not when the window is closed manually.
I don’t believe there is a way to tell those apart in WPF (though I’m not positive).
The way I always handled it in WinForms was to create a member variable “_Closing”, set it to false, and a method “ReallyClose()” that would set _Closing to true, then call Close. My Closing handler would then cancel the close if _Closing was not set to true.
Yeah, it’s a bit of a hack, but it worked.