다음을 통해 공유


WPF - Adding Winforms

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 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 – 01: **Run Visual Studio 2015 -> Visual C# -> Windows -> WPF Application

 

**Step – 02: **Right click on 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

Here you can find the both reference files added under References:

**Step – 03: **Add the following namespacing too

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

 

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

      <WindowsFormsHost>

            <wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>

        </WindowsFormsHost>

**Step – 04: **Now run the code by clicking on Start at the top pane of Visual Studio 2015

**You will be getting the following Window **

This application will allow you to enter the date in Windows Form at WPF 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.