ElementHost.Child 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置由 UIElement 控件承载的 ElementHost。
public:
property System::Windows::UIElement ^ Child { System::Windows::UIElement ^ get(); void set(System::Windows::UIElement ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.UIElement Child { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Child : System.Windows.UIElement with get, set
Public Property Child As UIElement
属性值
托管Windows Presentation Foundation (WPF) 元素。
- 属性
示例
下面的代码示例演示如何使用 Child 属性来分配托管的 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
注解
只能承载一个元素,但 Child 可以有任意数量的子元素。