使用英语阅读

通过


ElementHost.Child 属性

定义

重要

一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。

获取或设置由 UIElement 控件承载的 ElementHost

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.UIElement Child { get; set; }

属性值

托管Windows Presentation Foundation (WPF) 元素。

属性

示例

下面的代码示例演示如何使用 Child 属性来分配托管的 WPF 元素。 有关详细信息,请参阅演练:在 Windows 窗体 中承载三维 WPF 复合控件

C#
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);
}

注解

只能承载一个元素,但 Child 可以有任意数量的子元素。

适用于

产品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅