WindowsFormsHost.Child Eigenschaft

Definition

Ruft das vom WindowsFormsHost-Element gehostete untergeordnete Steuerelement ab oder legt dieses Element fest.

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

Eigenschaftswert

Control

Das gehostete Windows Forms Steuerelement.

Ausnahmen

Es wurde versucht, ein Formular der obersten Ebene als gehostetes Steuerelement zuzuweisen.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Die Child Eigenschaft zum Hinzufügen des WindowsFormsHost gehosteten Steuerelements zum Element verwendet wird. Weitere Informationen finden Sie unter Exemplarische Vorgehensweise: Hosten eines ActiveX Steuerelements in WPF.

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

Hinweise

Nur ein untergeordnetes Steuerelement kann gehostet werden, kann jedoch Child eine beliebige Anzahl von untergeordneten Elementen aufweisen.

Das untergeordnete Steuerelement kann kein Formular auf oberster Ebene sein.

Wenn Child es sich um eine Form, die Eigenschaft des Formulars ControlBox handelt, wird auf false.

XAML-Textverwendung

<Objekt >

<hostedControl .../>

</Objekt >

XAML-Werte

Objekt Ein WindowsFormsHost Element (oder eine mögliche Unterklasse).

hostedControl Ein Element, das das gehostete Windows Forms-Steuerelement angibt. Das Angeben des benutzerdefinierten Steuerelements im Markup erfordert in der Regel eine XMLns-Zuordnung, siehe XAML-Namespaces und Namespacezuordnung für WPF-XAML.

Gilt für

Siehe auch