Windows apps
Collapse the table of content
Expand the table of content
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 override Visual GetVisualChild (
	int index
)
protected Visual GetVisualChild (
	int index
)
protected override function GetVisualChild (
	index : int
) : Visual
You cannot use methods in XAML.

Parameters

index

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

Return Value

The requested child element. This should not return a null reference (Nothing in Visual Basic); if the provided index is out of range, an exception is raised.

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 raise 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 raises an exception. Several common elements, such as decorators, adorners, or elements with specialized renderers, 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.

// To store and manage the adorner's visual children.
VisualCollection visualChildren;

...

// Override the VisualChildrenCount and GetVisualChild properties to interface with 
// the adorner's visual collection.
protected override int VisualChildrenCount { get { return visualChildren.Count; } }
protected override Visual GetVisualChild(int index) { return visualChildren[index]; }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

Show:
© 2016 Microsoft