VisualTreeHelper.GetChild(DependencyObject, Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the child visual object from the specified collection index within a specified parent.
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
Parameters
- reference
- DependencyObject
The parent visual, referenced as a DependencyObject.
- childIndex
- Int32
The index that represents the child visual that is contained by reference
.
Returns
The index value of the child visual object.
Examples
The following example shows how to enumerate all the descendants of a visual object. This is a technique you might use if you are interested in serializing all the rendering information of a visual object hierarchy or are performing analysis or alternative rendering.
// 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
Remarks
Call the GetChildrenCount method to determine the total number of child elements of a parent visual.
The value of reference
can represent either a Visual or Visual3D object, which is why the common base type DependencyObject is used here as a parameter type.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기