VisualTreeHelper.GetChildrenCount(DependencyObject) Metoda

Definicja

Zwraca liczbę elementów podrzędnych, które zawiera określony obiekt wizualny.

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

Parametry

reference
DependencyObject

Wizualizacja nadrzędna, do którego odwołuje się element DependencyObject.

Zwraca

Int32

Liczba wizualizacji podrzędnych, które zawiera wizualizacja nadrzędna.

Przykłady

W poniższym przykładzie pokazano, jak wyliczyć wszystkie elementy podrzędne obiektu wizualizacji. Jest to technika, której można użyć, jeśli interesuje Cię serializacja wszystkich informacji o renderowaniu hierarchii obiektów wizualizacji lub przeprowadzania analizy lub renderowania alternatywnego.

// 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

Uwagi

GetChild Użyj metody , aby pobrać określony element podrzędny wizualizacji nadrzędnej.

Wartość reference może reprezentować obiekt Visual lub Visual3D , dlatego typ podstawowy DependencyObject jest używany tutaj jako typ parametru.

Dotyczy