WindowsFormsHost.Child Свойство

Определение

Возвращает или задает дочерний элемент управления, размещаемый в элементе 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

Значение свойства

Control

Размещенный элемент управления Windows Forms.

Исключения

Предпринята попытка назначить форму верхнего уровня размещаемым элементом управления.

Примеры

В следующем примере кода показано, как использовать Child свойство для добавления размещенного элемента управления в WindowsFormsHost элемент. Дополнительные сведения см. в пошаговом руководстве. Размещение элемента управления ActiveX в 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

Комментарии

Можно разместить только один дочерний элемент управления, но Child может иметь любое количество дочерних элементов.

Дочерний элемент управления не может быть формой верхнего уровня.

Если Child значение равно Form, свойству формы ControlBox присваивается значение false.

Использование текста XAML

< object >

<hostedControl .../>

</ object >

Значения XAML

Объекта Элемент WindowsFormsHost (или возможный подкласс).

hostedControl Элемент, указывающий размещенный элемент управления Windows Forms. Для указания пользовательского элемента управления в разметке обычно требуется сопоставление xmlns, см. раздел "Пространства имен XAML" и "Сопоставление пространств имен" для WPF XAML.

Применяется к

См. также раздел