We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to host WPF control in Windows Forms project?

It is possible to use Syncfusion WPF controls in Windows Forms Application by following below steps.

 

Step 1: Create Windows Forms and Windows Forms Control Library Application

 

Need to create Windows Forms application as shown in below screenshot.

 

Screenshot

Figure 1: Windows Forms Application

 

Need to create the Windows Control Library application as like in below.

Screenshot

Figure 2: Windows Forms Control Library Application

 

Step 2: Configure the required WPF assemblies

 

Need to add UserControl.Xaml file in Windows Forms Control Library Application and required Syncfusion WPF dependency assemblies.

For example

Here we are using the Syncfusion SfAccordion WPF control. So it is needed to add UserControl.xaml file into the project.

Screenshot

Figure 3: Adding UserControl.Xaml file into the WindowsControlLibrary application.

 

Then it is needed to add the necessary configuration for SfAccordion WPF control in the loaded UserControl.Xaml file.

The following code snippets explain the same.

Xaml

 

Step 3: Need to create Element Host class.

 

To load WPF control in Windows Forms application, it is needed to implement Class derived from ElementHost and load SfAccordion WPF control in it.

The following code snippet explains the same.

C#

 

 

VB

 

 

Step 4: Need to attach Windows Control Library project into Windows Forms application.

 

It is needed to attach the created Windows Control Library project into Windows Forms application and add it to its assembly reference section.

 

Step 5: Need to add SfAccordion control in Windows Forms application.

 

As both the applications are merged, it is needed to rebuild the whole application. It will add SfAccordion WPF control in Windows Forms Application Designer Page Toolbox. It can be dragged and dropped into the Form Designer.

Screenshot

  

 Figure 11: Loading WPF SfAccordion control into Windows Forms application.

 

And now it can be used in Windows Forms application.

Screenshot

   Figure 12: SfAccordion control can be used in Windows Forms Application.

 

Note

To run the Application and open the Form Designer, it is needed to rebuild this application.

 

Sample Links

C#: WPFControlsInWindowsForms

VB: WPFControlsInWindowsForms

Article ID: Published Date: Last Revised Date: Platform: Control:
7240 01/20/2017 01/25/2017 Windows Forms General
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.