WindowsFormsHost.Child Właściwość

Definicja

Pobiera lub ustawia kontrolkę podrzędną hostowaną WindowsFormsHost przez element .

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

Wartość właściwości

Control

Hostowana kontrolka Windows Forms.

Wyjątki

Podjęto próbę przypisania formularza najwyższego poziomu jako hostowanej kontrolki.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą właściwości dodać hostowaną Child kontrolkę do WindowsFormsHost elementu . Aby uzyskać więcej informacji, zobacz Przewodnik: hostowanie kontrolki ActiveX w 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

Uwagi

Może być hostowana tylko jedna kontrolka podrzędna, ale Child może mieć dowolną liczbę elementów podrzędnych.

Kontrolka podrzędna nie może być formularzem najwyższego poziomu.

Jeśli Child element ma Formwartość , właściwość formularza jest ustawiona ControlBox na falsewartość .

Użycie tekstu w języku XAML

<Obiektu >

<hostedControl .../>

</Obiektu >

Wartości XAML

Obiektu Element WindowsFormsHost (lub możliwa podklasa).

hostedControl Element określający hostowaną kontrolkę Windows Forms. Określenie niestandardowej kontrolki w znacznikach zwykle wymaga mapowania xmlns. Zobacz Przestrzenie nazw XAML i Mapowanie przestrzeni nazw dla języka WPF XAML.

Dotyczy

Zobacz też