Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a custom WPF control in WinForms

Tags:

.net

winforms

wpf

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.

like image 626
Gerrie Schenck Avatar asked Feb 11 '09 07:02

Gerrie Schenck


1 Answers

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

  • WPF Interoperation: "Airspace" and Window Regions Overview
  • Windows Forms and WPF Property Mapping
  • How to: Host a Windows Presentation Foundation Control in Windows Forms by Using ElementHost
  • Walkthrough: Hosting a Windows Forms Control in Windows Presentation Foundation
like image 53
rudigrobler Avatar answered Oct 17 '22 14:10

rudigrobler