Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

VisualTreeHelper.GetChild Method

Returns the child visual object from the specified collection index within a specified parent.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public static DependencyObject GetChild(
	DependencyObject reference,
	int childIndex
)

Parameters

reference
Type: System.Windows.DependencyObject

The parent visual, referenced as a DependencyObject.

childIndex
Type: System.Int32

The index that represents the child visual that is contained by reference.

Return Value

Type: System.Windows.DependencyObject
The index value of the child visual object.

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.

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);
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft