I have a window that I sometimes open using Show()
and sometimes using ShowDialog()
. In the second case, the returned dialog result is important for me. But if I set the DialogResult
after calling Show()
I get an InvalidOperationException
. Is there a way to find out which method was used to open the window and set or not the DialogResult
accordingly? Or is there another way?
Of course I know I can catch and ignore the exception, but I don't like this solution.
Use System.Windows.Interop.ComponentDispatcher.IsThreadModal inside the window to determine if it runs on a modal thread or not.
If you look at set_DialogResult in Reflector, it checks _showingAsDialog to determine whether the dialog is modal. Unfortunately this is a private field.
Do you always construct a new instance of the window before calling Show()/ShowDialog(). If so, you could pass an argument to the constructor indicating how it is to be shown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With