Search code examples
c#wpfmodal-dialogshowdialogdialogresult

How to determine if Window was launching as a modal using ShowDialog


I have a WPF Window created. I have some cases where i want to display it using ShowDialog() and others just using Show().

For the ShowDialog() i want to set the DialogResult which all works fine, however if the window is launched using Show() and i set the DialogResult i get the exception

DialogResult can be set only after Window is created and shown as dialog. 

How to i determine how the window was launched so i can place a condition on setting the DialogResult?


Solution

  • Check the Owner property on the child dialog. If Show() was used the child window Owner won't be set automatically but it should be when you use ShowDialog().