WindowsFormsHost Class
Assembly: WindowsFormsIntegration (in windowsformsintegration.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
[ContentPropertyAttribute("Child")] public class WindowsFormsHost : HwndHost, IKeyboardInputSink
/** @attribute ContentPropertyAttribute("Child") */
public class WindowsFormsHost extends HwndHost implements IKeyboardInputSink
ContentPropertyAttribute("Child") public class WindowsFormsHost extends HwndHost implements IKeyboardInputSink
<WindowsFormsHost.../>
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 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="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>
<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>
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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Reference
WindowsFormsHost MembersSystem.Windows.Forms.Integration Namespace
ElementHost
Other Resources
Property MappingWalkthrough: Hosting a Windows Forms Control in Windows Presentation Foundation
Walkthrough: Hosting an ActiveX Control in Windows Presentation Foundation
Supported Scenarios in Windows Presentation Foundation and Windows Forms Interoperation
Migration and Interoperability
Note: