tags:

views:

547

answers:

2

I'm going to have to build a custom control for a WinForms application. But in the near future that same control will have to be used in a WPF application.

I've already written all the logic in a controller class which I can use for both WinForms and WPF (I will only have some databinding to do and that's it), but of course it would be easier to develop and maintain the control only once.

So can I build the control in WPF and then put them on a WinForms form? My projects currently have 3.0 as their target framework.

A: 

Did some more research and it's possible. ATM I'm watching this screencast: http://channel9.msdn.com/posts/DanielMoth/Use-WPF-from-Windows-Forms-projects-in-Visual-Studio-2008/ which gives a nice short introduction.

Gerrie Schenck
+6  A: 

Yes you can!

In WinForms use ElementHost and add you WPF control inside (Best practice here is to create a WPF User Control and add you controls into the user control)

And in WPF, if you want to use a WinForms user control, use the WindowsFormsHost

rudigrobler
Here's one more useful link, an article I just had published on Simple-Talk.com called "Mixing WPF and WinForms" (http://www.simple-talk.com/dotnet/.net-framework/mixing-wpf-and-winforms/).Unlike any other article I have seen out there, I walk you through hosting WPF in WinForms and WinForms in WPF in tandem, side-by-side articles.
msorens