A Windows Forms control that can be used to host a Windows Presentation Foundation (WPF) element.
Namespace:
System.Windows.Forms.Integration
Assembly:
WindowsFormsIntegration (in WindowsFormsIntegration.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
<ContentPropertyAttribute("Child")> _
Public Class ElementHost _
Inherits Control
Dim instance As ElementHost
[ContentPropertyAttribute("Child")]
public class ElementHost : Control
[ContentPropertyAttribute(L"Child")]
public ref class ElementHost : public Control
public class ElementHost extends Control
XAML Object Element Usage
<ElementHost>
Child
</ElementHost>
Use the ElementHost control to place a WPF UIElement on your Windows Forms control or form.
To host a Windows Forms control in a WPF element, use the WindowsFormsHost element.
Note: |
|---|
WindowsFormsIntegration.dll is installed with the WPF assemblies. The default location for the assembly is %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll. |
To host a WPF element in a Windows Form, you must assign the WPF element to the Child property.
Use the PropertyMap property to assign custom mappings between an ElementHost control and its hosted WPF element. For more information, see Windows Forms and WPF Property Mapping.
The following code example demonstrates how to use the ElementHost control to host a WPF element. For more information, see Walkthrough: Hosting a Windows Presentation Foundation Composite Control in Windows Forms.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the ElementHost control for hosting the
' WPF UserControl.
Dim host As New ElementHost()
host.Dock = DockStyle.Fill
' Create the WPF UserControl.
Dim uc As New HostingWpfUserControlInWf.UserControl1()
' Assign the WPF UserControl to the ElementHost control's
' Child property.
host.Child = uc
' Add the ElementHost control to the form's
' collection of child controls.
Me.Controls.Add(host)
End Sub
private void Form1_Load(object sender, EventArgs e)
{
// Create the ElementHost control for hosting the
// WPF UserControl.
ElementHost host = new ElementHost();
host.Dock = DockStyle.Fill;
// Create the WPF UserControl.
HostingWpfUserControlInWf.UserControl1 uc =
new HostingWpfUserControlInWf.UserControl1();
// Assign the WPF UserControl to the ElementHost control's
// Child property.
host.Child = uc;
// Add the ElementHost control to the form's
// collection of child controls.
this.Controls.Add(host);
}
System..::.Object
System..::.MarshalByRefObject
System.ComponentModel..::.Component
System.Windows.Forms..::.Control
System.Windows.Forms.Integration..::.ElementHost
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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.
.NET Framework
Supported in: 3.5, 3.0
Reference
Other Resources