WPF with Forms Window

Status
Not open for further replies.

complete

Seniorius Lurkius
36
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:
Code:
                        dres = form.ShowDialog();
                        if (dres != DialogResult.OK) return;

The compiler is complaining:

Code:
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?)
 
I've been starting to mess around with WPF recently, and have to say the error messages don't offer much help.

But I think this might be a namespace problem. Try changing it to

Code:
if (dres != System.Windows.Forms.DialogResult.OK) return;

and see if it makes any difference.

ADDED:
You'll also need to add a reference (Project Menu | Add Reference, in the .Net section) to System.Windows.Forms to make it work.
 

QuadDamaged

Ars Praefectus
3,983
Subscriptor++
It's a namespace issue allright but I think you'll find that form is a WPF window, innit?


Code:
public bool? ShowDialog() // in class System.Windows.Window, PresentationFramework

public DialogResult ShowDialog() // in class System.Windows.Forms.Form, System.Windows.Form


The compiler tells you that you are currently calling ShowDialog on a WPF window and that there's no implicit cast between bool? and System.Windows.Forms.DialogResult

Fix: Call ShowDialog on a Forms window, or use the WPF-style ShowDialog result.

Cheers,
Palad1
 
Status
Not open for further replies.