Jason
Jason

Reputation: 17099

Mixing WPF with a WinForm application?

My fairly large WinForm application needs a GUI overhaul, but I can't afford to do it all at once. I need to know if I can slowly add WPF into it, and if so, how?

Can I add WPF dialogs?

Can I add WPF 'panels' within a WinForm so that I can embed WPF elements?

EDIT

Can I do the opposite and put WinForm dialogs in my WPF application?

Upvotes: 11

Views: 5584

Answers (3)

mark_h
mark_h

Reputation: 5487

You can use the ElementHost control found in the System.Windows.Forms.Integration namespace. You will need a reference to the WindowsFormsIntegration assembly (in WindowsFormsIntegration.dll)

This control is an empty container into which you can put WPF controls e.g.

myElementHost.Child = someWpfControl;

You can find it in your toolbox and drag and drop it onto a winform like any other control;

enter image description here

Upvotes: 0

Sam
Sam

Reputation: 29009

Yep, I've successfully mixed winforms and WPF. I even managed to add WPF windows to win32 apps, changed this app to a dll and used a WPF app to show win32 windows which show WPF windows.

To host WPF windows in WinForm or win32 apps you will need this line befor you .Show() your WpfWindow:

System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(myWpfWindow); 

See http://msdn.microsoft.com/en-us/library/aa348549.aspx

Upvotes: 6

Related Questions