Condividi tramite


WindowsFormsHost.Child Proprietà

Definizione

Ottiene o imposta il controllo figlio ospitato dall'elemento 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

Valore della proprietà

Controllo Windows Form ospitato.

Eccezioni

È stato effettuato un tentativo di assegnare un modulo di primo livello come controllo ospitato.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare la proprietà Child per aggiungere il controllo ospitato all'elemento WindowsFormsHost. Per altre informazioni, vedere Procedura dettagliata: Hosting di un controllo ActiveX 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

Commenti

È possibile ospitare un solo controllo figlio, ma Child può avere un numero qualsiasi di elementi figlio.

Il controllo figlio non può essere un modulo di primo livello.

Se Child è un Form, la proprietà ControlBox della maschera viene impostata su false.

Utilizzo del testo XAML

< oggetto>

< hostedControl.../>

</ oggetto>

Valori XAML

oggetto un elemento WindowsFormsHost (o una sottoclasse possibile).

hostedControl Elemento che specifica il controllo Windows Form ospitato. Specificare il controllo personalizzato nel markup richiede in genere un mapping xmlns, vedere spazi dei nomi XAML e mapping dello spazio dei nomi per XAML WPF.

Si applica a

Vedi anche