Can I place a WinForm form in a WPF form through a container / wrapper?

Is there a way to place / display the full form of WinForms (and not just one control) in some kind of container or shell control type in a WPF form? I am looking for something similar in concept for virtual, including php or iframe in html. Perhaps compiling it to OCX or DLL.

+6
c # visual-studio-2008 wpf
source share
3 answers

As far as I know, you cannot place a real WinForms form in WPF.

However, a good alternative is to create a regular UserControl in WinForms (like a Windows Forms Control Library project) that contains all the necessary functions and child controls.

Then, in your WPF project, refer to the WindowsFormsIntegration.dll file (should be on the .NET tab in Add References).

Then also reference the assembly containing the WinForms UserControl, and finally add the WindowsFormsHost container to the XAML.

See this helpful tutorial from Sacha Barber for more information.

+6
source share

you can do it with the following code:

In your XAML:

<WindowsFormsHost name="wfHost" /> 

In your code:

 Form foo = new Form(); foo.TopLevel = false; foo.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; wfHost.Child = foo; 
+16
source share

There is an article on CodeProject that shows how to place exe as a control in WinForms (this application uses Tab, drag Winform.exe onto it, it creates a tab with this window in it), obtained from this article here . I know that you specifically asked for WPF, but maybe this can lead you in the right direction?

Hope this helps, Regards, Tom.

+1
source share

All Articles