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 フォーム コントロール。

例外

トップレベルのフォームをホストされるコントロールとして割り当てようとしました。

次のコード例は、プロパティを使用 Child して、ホストされたコントロールを要素に追加する方法を WindowsFormsHost 示しています。 詳細については、「チュートリアル: WPF でのActiveX コントロールのホスト」を参照してください。

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

注釈

ホストできる子コントロールは 1 つだけですが Child 、任意の数の子を持つことができます。

子コントロールを最上位のフォームにすることはできません。

場合 ChildForm、フォームの ControlBox プロパティがに false設定されます。

XAML テキストの使用法

< object >

<hostedControl .../>

</ object >

XAML 値

オブジェクトWindowsFormsHost要素 (または可能なサブクラス)。

hostedControl ホストされるWindows フォーム コントロールを指定する要素。 マークアップでカスタム コントロールを指定するには、通常、xmlns マッピングが必要です。 WPF XAML の XAML 名前空間と名前空間マッピングに関するページを参照してください。

適用対象

こちらもご覧ください