Tim
Tim

Reputation: 1344

Opening winform from wpf application programmatically

How would I go about opening a winform from a wpf application? This needs to be done through code, but the normal function

Form.Show(); 

will not work. I need something that will allow me to change the visibility of the form, but I am not able to access any of the gui related functions within this form.

Upvotes: 3

Views: 6286

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564851

You can work with the Windows Form the same way in a WPF application as you would from a Windows Forms application, provided you have the proper references. This should work fine:

YourForm form = new YourForm();
form.Show();

However, I would typically recommend trying to rework this to include the Windows Forms content as a UserControl within a WPF Window using a WindowsFormsHost control. This tends to be a little cleaner, since the window parenting works a bit more cleanly (since they're all WPF windows).

Upvotes: 3

Related Questions