WindowsFormsHost.Child Propriedade

Definição

Obtém ou define o controlo filho hospedado pelo WindowsFormsHost elemento.

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

Valor de Propriedade

O controlo do Windows Forms hospedado.

Exceções

Foi feita uma tentativa de atribuir um formulário de topo como controlo hospedado.

Exemplos

O exemplo de código seguinte demonstra como usar a Child propriedade para adicionar o controlo hospedado ao WindowsFormsHost elemento. Para mais informações, consulte Walkthrough: Hospedar um Controlo ActiveX em 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

Observações

Apenas um controlo filho pode ser alojado, mas Child pode ter qualquer número de filhos.

O controlo da criança não pode ser uma forma de nível superior.

Se Child for um Form, a propriedade da ControlBox forma é definida como false.

Utilização de Texto XAML

< objeto>

< hostedControl.../>

</ objeto>

Valores XAML

Objeto Um WindowsFormsHost elemento (ou uma possível subclasse).

hostedControl Um elemento que especifica o controlo Windows Forms hospedado. Especificar o controlo personalizado em marcação normalmente requer um mapeamento xmlns, veja XAML Namespaces e Namespace Mapping para WPF XAML.

Aplica-se a

Ver também