views:

28

answers:

1

I'm working with an existing WinForms form. I'm trying to interface a new WPF Window with it (to replace an old form). The old code called mainForm.AddOwnedForm(newForm);.

I know that that makes the new form somewhat of a child of the main form -- it's hidden when the main form is, etc.

Is there a way for me to link a WPF window to the main form in the same way?

Obviously, WinForms doesn't know about WPF, so I'm not expecting an AddOwnedWindow method or anything. But is there a way to emulate this functionality?

A: 

I figured it out.

WindowInteropHelper will do it:

var newWindow = new WPFWindow();
var helper = new WindowInteropHelper(newWindow) {Owner = mainForm.Handle};

Thanks to this source.

NickAldwin