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.

FrameworkElement::GetVisualChild Method

Overrides Visual::GetVisualChild, and returns a child at the specified index from a collection of child elements.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

protected:
virtual Visual^ GetVisualChild(
	int index
) override

Parameters

index
Type: System::Int32

The zero-based index of the requested child element in the collection.

Return Value

Type: System.Windows.Media::Visual
The requested child element. This should not return nullptr; if the provided index is out of range, an exception is thrown.

In the FrameworkElement implementation, the only valid index is zero. The content model for GetVisualChild supports either zero or one child elements, not a collection.

Notes to Inheritors

This implementation is only valid for elements that do not maintain any more descriptive collection of visual child elements. Any element that does have such a collection must override this method and map the index to an equivalent index in the child element collection that is supported by that element. An index in the range from zero to VisualChildrenCount (minus one) should return a valid element; any other index should throw an out-of-range exception. An example of an element type that does support a child collection and overrides GetVisualChild to return more than one possible child is Panel.

The default implementation in FrameworkElement presumes only one visual child. Any value passed for index other than zero causes an exception to be thrown. Several common elements, such as decorators, adorners, or elements with specialized rendering, override the FrameworkElement implementation (of the implementation from intermediate base classes). Some implementations still enforce one visual child whereas others allow a collection.

The following example shows how a custom adorner uses the values declared by a VisualCollection that it maintains for its multiple visual children. These values are reported through overrides of VisualChildrenCount and GetVisualChild.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 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