WindowsFormsHost.Child 属性

定义

获取或设置由 WindowsFormsHost 元素托管的子控件。

public:
 property System::Windows::Forms::Control ^ Child { System::Windows::Forms::Control ^ get(); void set(System::Windows::Forms::Control ^ value); };
public System.Windows.Forms.Control Child { get; set; }
member this.Child : System.Windows.Forms.Control with get, set
Public Property Child As Control

属性值

托管的 Windows 窗体控件。

例外

尝试将顶级窗体分配为托管控件。

示例

下面的代码示例演示如何使用 Child 属性将托管控件添加到 WindowsFormsHost 元素。 有关详细信息,请参阅 演练:在 WPF中托管 ActiveX 控件。

private void Window_Loaded(object sender, RoutedEventArgs e) 
{
    // Create the interop host control.
    System.Windows.Forms.Integration.WindowsFormsHost host =
        new System.Windows.Forms.Integration.WindowsFormsHost();

    // Create the ActiveX control.
    var axWmp = new WmpAxLib.AxWindowsMediaPlayer();

    // Assign the ActiveX control as the host control's child.
    host.Child = axWmp;

    // Add the interop host control to the Grid
    // control's collection of child controls.
    this.grid1.Children.Add(host);

    // Play a .wav file with the ActiveX control.
    axWmp.URL = @"C:\Windows\Media\tada.wav";
}
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

    ' Create the interop host control.
    Dim host As New System.Windows.Forms.Integration.WindowsFormsHost()

    ' Create the ActiveX control.
    Dim axWmp As New AxWMPLib.AxWindowsMediaPlayer()

    ' Assign the ActiveX control as the host control's child.
    host.Child = axWmp

    ' Add the interop host control to the Grid
    ' control's collection of child controls.
    Me.grid1.Children.Add(host)

    ' Play a .wav file with the ActiveX control.
    axWmp.URL = "C:\Windows\Media\tada.wav"

End Sub

注解

只能托管一个子控件,但 Child 可以具有任意数量的子控件。

子控件不能是顶级窗体。

如果 ChildForm,则窗体的 ControlBox 属性设置为 false

XAML 文本用法

< 对象>

< hostedControl.../>

</ 对象>

XAML 值

对象 A WindowsFormsHost 元素(或可能的子类)。

hostedControl 指定托管 Windows 窗体控件的元素。 在标记中指定自定义控件通常需要 xmlns 映射,请参阅 WPF XAML 的 XAML 命名空间和命名空间映射

适用于

另请参阅