Collection Object (Abstract)

Represents a collection of objects.

XAML
Must use derived objects.
Scripting
Must use derived objects.

Properties

Count, Name

Methods

Add, Clear, Equals, FindName, GetHost, GetItem, GetValue, Insert, Remove, RemoveAt, SetValue

Derived Objects

ColorKeyFrameCollection, DoubleKeyFrameCollection, GeometryCollection, GradientStopCollection, Inlines, PathFigureCollection, PathSegmentCollection, TransformCollection, TriggerCollection, VisualCollection

Remarks

Collection is abstract. To use a collection in JavaScript, you must use one of the following derived collection types:

Collections in Silverlight are obtained by getting the values of certain properties that reference the object representing the collection. In some cases, this property is read-only. A read-only collection property implies that the object that owns the collection defines the collection when it is created, and that you cannot replace that collection with a new collection object. A read-only collection property does not imply that you cannot adjust the collection contents. To adjust the collection contents, get the collection property value, use it as an object reference, and call Collection methods on it.

For collection properties that are read-write, you can replace the collection. This is useful because if you use CreateFromXaml, and you want to replace all the items in an existing collection, you can declare the collection in question as the root element for the XAML you submit to CreateFromXaml, and then set the collection property to the CreateFromXaml return value.

You can access the child objects of a parent object (the object that holds the relevant collection property) by using the methods of the Collection object. The most common collection used for this purpose is the VisualCollection that is the value of the Canvas.Children property.

Classes derived from Collection also have access to methods of DependencyObject, and can have a declared Name in XAML.

For more information on using properties and methods of the Collection object, see Referencing and Modifying Silverlight Objects.

Examples

The following JavaScript example shows how to retrieve the collection of an object and access the members of the collection:

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

See Also

Referencing and Modifying Silverlight Objects
ColorKeyFrameCollection
DoubleKeyFrameCollection
GeometryCollection
GradientStopCollection
Inlines
PathFigureCollection
PathSegmentCollection
TransformCollection
TriggerCollection
VisualCollection