Is there a clever way to detect whether a window was closed by
- A user pressing the (X) button in the upper right corner of the window or
- window.Close() has been called programatically.
I would like to detect this in the window.Closing handler.
I could set a flag whenever I call window.Close(), but this is not a very pretty solution.
I’m not sure I like this at all but it’s a question that you obviously have a reason for asking. if you were to take a stack trace in the OnClosing event you could look up for the Window.Close event.