* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
3.3 KiB
title, titleSuffix, ms.date, helpviewer_keywords, ms.assetid
| title | titleSuffix | ms.date | helpviewer_keywords | ms.assetid | |
|---|---|---|---|---|---|
| Host a Windows Forms control in WPF using XAML | 03/30/2017 |
|
1aef42cb-4cfb-44b4-9a7a-c02632d3d9c7 |
Walkthrough: Hosting a Windows Forms Control in WPF by Using XAML
[!INCLUDETLA2#tla_winclient] provides many controls with a rich feature set. However, you may sometimes want to use Windows Forms controls on your [!INCLUDETLA2#tla_winclient] pages. For example, you may have a substantial investment in existing Windows Forms controls, or you may have a Windows Forms control that provides unique functionality.
This walkthrough shows you how to host a Windows Forms xref:System.Windows.Forms.MaskedTextBox?displayProperty=nameWithType control on a [!INCLUDETLA2#tla_winclient] page by using [!INCLUDETLA2#tla_xaml].
For a complete code listing of the tasks shown in this walkthrough, see Hosting a Windows Forms Control in WPF by Using XAML Sample.
Prerequisites
You need Visual Studio to complete this walkthrough.
Hosting the Windows Forms Control
To host the MaskedTextBox control
-
Create a WPF Application project named
HostingWfInWpfWithXaml. -
Add references to the following assemblies.
-
WindowsFormsIntegration
-
System.Windows.Forms
-
-
Open MainWindow.xaml in the WPF Designer.
-
In the xref:System.Windows.Window element, add the following namespace mapping. The
wfnamespace mapping establishes a reference to the assembly that contains the Windows Forms control.xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" -
In the xref:System.Windows.Controls.Grid element add the following XAML.
The xref:System.Windows.Forms.MaskedTextBox control is created as a child of the xref:System.Windows.Forms.Integration.WindowsFormsHost control.
[!code-xamlHostingWfInWpfWithXaml#3]
-
Press F5 to build and run the application.
See also
- xref:System.Windows.Forms.Integration.ElementHost
- xref:System.Windows.Forms.Integration.WindowsFormsHost
- Design XAML in Visual Studio
- Walkthrough: Hosting a Windows Forms Control in WPF
- Walkthrough: Hosting a Windows Forms Composite Control in WPF
- Walkthrough: Hosting a WPF Composite Control in Windows Forms
- Windows Forms Controls and Equivalent WPF Controls
- Hosting a Windows Forms Control in WPF by Using XAML Sample