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 窗体 中承载三维 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 窗体控件或窗体上。

若要在 WPF 元素中承载Windows 窗体控件,请使用 WindowsFormsHost 元素。

WindowsFormsIntegration.dll随 WPF 程序集一起安装。 程序集的默认位置为 %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll。

若要在 Windows 窗体中承载 WPF 元素,必须将 WPF 元素分配给 Child 属性。

PropertyMap 使用 属性在控件与其托管的 ElementHost WPF 元素之间分配自定义映射。 有关详细信息,请参阅 Windows 窗体和 WPF 属性映射

即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅: https://aka.ms/ContentUserFeedback

提交和查看相关反馈