Using a custom WPF control in WinForms
Asked Answered
G

1

18

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.

Gelinas answered 11/2, 2009 at 7:46 Comment(1)
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.Gelinas
K
18

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

Kisor answered 11/2, 2009 at 8:45 Comment(1)
Here's one more useful link, an article I just had published on Simple-Talk.com called "Mixing WPF and WinForms" (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.Suck

© 2022 - 2024 — McMap. All rights reserved.