Export (0) Print
Expand All

GetItem Method

Retrieves the object from the collection at the specified index.

XAML
Cannot use methods in XAML.
Scripting
retval = object.GetItem(index)

Parameters

index

integer

The index at which the object should be retrieved.

Return Value

object

Returns a reference to the object if successful; otherwise, returns null.

Remarks

The type of item you retrieve depends on the collection. Some collections expect only one object type, but others such as VisualCollection can contain multiple object types that share a common base type.

Examples

You can retrieve a specific child of a parent object by referencing the index of the collection of the parent object. The following JavaScript example shows how to retrieve a child of a parent Canvas object by using the GetItem method:

JavaScript
function getObject(parent, index)
{
    // Determine if the index is valid.
    if (index < parent.children.count)
    {
        // Retrieve the child object at the specified index in the collection.
        var object = parent.children.getItem(index);
    }

    return object;
}

Enumerating Child Objects

You can enumerate the child of a parent object by accessing the children collection of the parent object. The following JavaScript example shows how to enumerate the children of a parent Canvas object by using the GetItem method:

JavaScript
function getChildren(parent, index)
{
    // Enumerate the children of the Canvas object.
    for (i = 0; i < parent.children.count; i++)
    {
        var child = parent.children.getItem(i);

        // Display the index and type of the child object.
        alert(i + ": " + child.toString());
    }
}

Applies To

ColorKeyFrameCollection, DoubleKeyFrameCollection, GradientStopCollection, Inlines, PathFigureCollection, PathSegmentCollection, PointKeyFrameCollection, StrokeCollection, StylusPointCollection, TriggerActionCollection, TriggerCollection, VisualCollection

See Also

Referencing and Modifying Silverlight Objects
Insert

Community Additions

Show:
© 2014 Microsoft