tags:

views:

88

answers:

2

How do I work with WIndows Forms in WPF?

In my WPF program I created a Windows Form class. In this Form, I placed an OK button and I went into the properties of the button and set the DialogResult to OK. Now, I am calling this Dialog (Window Form) from the MainWindow.xaml.cs:

     DialogResult dres;
     dres = form.ShowDialog();
     if (dres != DialogResult.OK) return;

The compiler is complaining:

Error   3   'System.Nullable<bool>' does not contain a definition for 'OK' and no extension method 'OK' 
accepting a first argument of type 'System.Nullable<bool>' could be found (are you missing a using directive 
or an assembly reference?)
A: 

That's because you should compare the DialogResult property of the form object, not the object it's self. Replace it with this and it should work:

if( dres.DialogResult != DialogResult.OK ) return;
jlafay
dres is defined like this: DialogResult dres; So System.Windows.Forms.DialogResult' does not contain a definition for 'DialogResult'.
xarzu
+2  A: 

The compiler is finding another definition of DialogResult, probably somewhere in your code. Spell its name out completely to avoid the ambiguity:

 System.Windows.Forms.DialogResult dres;
 dres = form.ShowDialog();
 if (dres != System.Windows.Forms.DialogResult.OK) return;
Hans Passant
The first occurrence doesn't need to be changed, but the second occurrence needs to; the compiler finds the DialogResult property of the class instead of the DialogResult enum here.
Francis Gagné