1

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?

CathalMF
  • 9,705
  • 6
  • 70
  • 106

2 Answers2

1

There could be multiple solutions, one of them could be override the ShowDialog() and show() method so you can send an parameter to determine in which way it was call. Or just set up an boolean flag on the class.

bugs2919
  • 371
  • 1
  • 8
-1

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().

James Lucas
  • 2,452
  • 10
  • 15
  • 1
    Setting the Owner has nothing to do with being modal. You're re-purposing the Owner property as a flag for something else and could lead to confusion down the road. – Nick Aug 11 '16 at 16:34