Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can WPF and WinForms be mixed within an application?

Tags:

winforms

wpf

Can both WPF and Windows forms controls be used within one application? How difficult or practical an idea is this?

like image 899
P a u l Avatar asked Feb 01 '09 18:02

P a u l


People also ask

Can you mix WPF and WinForms?

Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms.

What is WPF being replaced with?

Universal Windows Platform. Both Windows Forms and WPF are old, and Microsoft is pointing developers towards its Universal Windows Platform (UWP) instead.

Is WPF harder than WinForms?

It is simple to use WinForms as controls can be used easily, it's less time-consuming and less tricky as compared to WPF.


2 Answers

It is fairly straightforward to host WPF controls in a WinForms app with an ElementHost adapter or WinForms controls in a WPF app with a WindowsFormsHost adapter. There are not too many resources on the web showing how to do either of these, however. In the process of learning how to do this for myself I quickly discovered the inherent symmetries between the two pathways. I distilled all my notes into an article comparing and contrasting these symmetries using a unique approach: the article is really two side-by-side articles, comparing every step in detail, starting from creating a user control in one technology to hosting it in an application in the "opposite" technology. My article, published on SimpleTalk.com in August 2010 is available here: Mixing WPF and WinForms.

For completeness, here are a couple good MSDN references, one for each pathway. In fact, the demo solution accompanying my article started from both of these:

  • Hosting a Windows Forms Composite Control in WPF
  • Hosting a WPF Control in Windows Forms
like image 176
Michael Sorens Avatar answered Oct 21 '22 19:10

Michael Sorens


I believe there is a WindowsFormsHost control you can put in your WPF apps which will do interop back to WinForms code:

http://blogs.msdn.com/ivo_manolov/archive/2007/07/26/wpf-win32-interop-part-1-hosting-winforms-controls-in-wpf-windows.aspx

like image 43
Dave Markle Avatar answered Oct 21 '22 17:10

Dave Markle