VisualTreeHelper.GetChild(DependencyObject, Int32) メソッド

定義

指定した親内の指定したコレクション インデックス位置から子ビジュアル オブジェクトを返します。

public:
 static System::Windows::DependencyObject ^ GetChild(System::Windows::DependencyObject ^ reference, int childIndex);
public static System.Windows.DependencyObject GetChild (System.Windows.DependencyObject reference, int childIndex);
static member GetChild : System.Windows.DependencyObject * int -> System.Windows.DependencyObject
Public Shared Function GetChild (reference As DependencyObject, childIndex As Integer) As DependencyObject

パラメーター

reference
DependencyObject

DependencyObject として参照される親ビジュアル。

childIndex
Int32

reference に含まれる子ビジュアル表すインデックス。

戻り値

子ビジュアル オブジェクトのインデックス値。

次の例は、ビジュアル オブジェクトのすべての子孫を列挙する方法を示しています。 これは、ビジュアル オブジェクト階層のすべてのレンダリング情報をシリアル化する場合、または分析または代替レンダリングを実行する場合に使用できる手法です。

// Enumerate all the descendants of the visual object.
static public void EnumVisual(Visual myVisual)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
    {
        // Retrieve child visual at specified index value.
        Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

        // Do processing of the child visual object.

        // Enumerate children of the child visual object.
        EnumVisual(childVisual);
    }
}
' Enumerate all the descendants of the visual object.
Public Shared Sub EnumVisual(ByVal myVisual As Visual)
    For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(myVisual) - 1
        ' Retrieve child visual at specified index value.
        Dim childVisual As Visual = CType(VisualTreeHelper.GetChild(myVisual, i), Visual)

        ' Do processing of the child visual object.

        ' Enumerate children of the child visual object.
        EnumVisual(childVisual)
    Next i
End Sub

注釈

メソッドを GetChildrenCount 呼び出して、親ビジュアルの子要素の合計数を確認します。

reference値は、 または Visual3D オブジェクトをVisual表すことができます。このため、ここでは共通の基本型DependencyObjectがパラメーター型として使用されます。

適用対象