P a u l
P a u l

Reputation: 7911

Can WPF and WinForms be mixed within an application?

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

Upvotes: 45

Views: 24702

Answers (6)

Michael Sorens
Michael Sorens

Reputation: 36698

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:

Upvotes: 44

Dominic Hopton
Dominic Hopton

Reputation: 7292

When hosting non-WPF content (Be it HTML, WinForms, or Win32 content), you will haveAirspace issues. This means you can't completely compost the WPF content with the hosted content. You also can't animate it etc. There are some interesting issues with respect to scrollviewers see here for more details and a fix also.

Upvotes: 4

Paul Stovell
Paul Stovell

Reputation: 32715

Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms. www.novamind.com's mind-mapping application is a successful mix of the two technologies.

Upvotes: 2

Donnelle
Donnelle

Reputation: 5719

We hosted significantly complex WPF controls in an existing LOB WinForms app. It can be done, but we did have issues (some no doubt caused by the steep learning curve). These primarily had to do with loss-of-focus events not being fired when expected, and also keyboard navigation issues.

Upvotes: 4

Andy
Andy

Reputation: 30418

You can also use an HWNDSource and HWNDHost controls to embed WPF controls in a WinForms (or any Win32, really) app.

Upvotes: 3

Dave Markle
Dave Markle

Reputation: 97671

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

Upvotes: 17

Related Questions