Freigeben über


WindowsFormsHost.Child Eigenschaft

Definition

Dient zum Abrufen oder Festlegen des untergeordneten Steuerelements, das WindowsFormsHost vom Element gehostet wird.

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

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 verwendet wird, um dem WindowsFormsHost Element das gehostete Steuerelement hinzuzufügen. 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

Es kann nur ein untergeordnetes Steuerelement gehostet werden, aber Child über eine beliebige Anzahl von untergeordneten Elementen verfügen.

Das untergeordnete Steuerelement kann kein Formular der obersten Ebene sein.

Wenn Child es sich um ein FormFormular handelt, wird die Eigenschaft des Formulars ControlBox 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. Die Angabe des benutzerdefinierten Steuerelements im Markup erfordert in der Regel eine XMLns-Zuordnung, siehe XAML-Namespaces und Namespacezuordnung für WPF-XAML.

Gilt für:

Weitere Informationen