Adding Winforms in WPF

Introduction

Here, we will be working with adding Windows Forms in Windows Presentation Foundation (WPF)

What is Winform?

Windows Form is a segment of Microsoft .NET framework. It is a GUI (Graphical User Interface) class library, which allows us to write the rich looking Client Applications for tablets, laptops and Desktops.

Development Requirements

  1. Visual Studio 2015
  2. .NET Framework 4.6
  3. Microsoft Expression Blend if needed

Follow the following steps to add Winforms in WPF:

Step 1: Run Visual Studio 2015 -> Visual C# -> Windows -> WPF Application

WPF Application

Step 2: Right click on the references and add the following reference files:

  • WindowsFormsIntegration
  • System.Windows.Forms

WindowsFormsIntegeration:

Click here to know about WindowsFormsIntegeration Namespace.

System.Windows.Forms:

Click here to know about System.Windows.Forms Namespace

References

References

References

Here, you can find both the reference files that are added under references.

References

Step 3: Add the following namespacing too,

xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

Now, paste the code, given below, at MainWindow.xaml under Grid or drag and drop the WindowsFormHost tool.

  1. <WindowsFormsHost>  
  2.     <wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000" />   
  3. </WindowsFormsHost>  
namespacing

Step 4: Now, run the code by clicking Start at the top pane of Visual Studio 2015.

pane

pane

You will be getting the following Window:

application

This Application will allow you to enter the date in Windows Form at WPF Application.

application

Summary

This is a basic example to work with Windows Forms on WPF (Windows Presentation Foundation). WPF is a new technology compared to Winforms.

Up Next
    Ebook Download
    View all
    Learn
    View all