public ref class ElementHost : System::Windows::Forms::Control
[System.Windows.Markup.ContentProperty("Child")]
public class ElementHost : System.Windows.Forms.Control
[<System.Windows.Markup.ContentProperty("Child")>]
type ElementHost = class
inherit Control
Public Class ElementHost
Inherits Control
ElementHost
下列程式碼範例示範如何使用
ElementHost
控制項來裝載 WPF 專案。 如需詳細資訊,請參閱
逐步解說:在 Windows Forms 中裝載 3D WPF 複合控制項
。
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);
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
使用
ElementHost
控制項,將 WPF
UIElement
放在Windows Forms控制項或表單上。
若要在 WPF 專案中裝載Windows Forms控制項,請使用
WindowsFormsHost
元素。
WindowsFormsIntegration.dll與 WPF 元件一起安裝。 元件的預設位置是 %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll。
若要在 Windows Form 中裝載 WPF 元素,您必須將 WPF 元素指派給
Child
屬性。
PropertyMap
使用 屬性,在控制項與其裝載的 WPF 專案之間
ElementHost
指派自訂對應。 如需詳細資訊,請參閱
Windows Form 和 WPF 屬性對應
。