WindowsFormsHost Class
An element that allows you to host a Windows Forms control on a WPF page.
Assembly: WindowsFormsIntegration (in WindowsFormsIntegration.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Use the WindowsFormsHost element to place a Windows Forms control within your WPF element or page.
To host a WPF element in a Windows Forms control or form, use the ElementHost control.
Note: |
|---|
WindowsFormsIntegration.dll is installed with the Windows Presentation Foundation (WPF) assemblies. The default location for the assembly is %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll. |
To host a Windows Forms control in a WPF element, you must assign the Windows Forms control to the Child property.
Use the PropertyMap property to assign custom mappings between a WindowsFormsHost element and its hosted Windows Forms control. For more information, see Windows Forms and WPF Property Mapping.
The following code example demonstrates how to use a WindowsFormsHost element to host a System.Windows.Forms.MaskedTextBox control. For more information, see Walkthrough: Hosting a Windows Forms Control in Windows Presentation Foundation by Using XAML.
<Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="HostingWfInWpf" > <Grid> <WindowsFormsHost> <wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/> </WindowsFormsHost> </Grid> </Window>
<Window x:Class="HostingWfInWpf.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="HostingWfInWpf" > <Grid> <WindowsFormsHost> <wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/> </WindowsFormsHost> </Grid> </Window>
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Interop.HwndHost
System.Windows.Forms.Integration.WindowsFormsHost
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: