Count Property

Gets the number of items contained in the collection.

Cannot be used in XAML.
value = object.Count

Property Value


The number of items contained in the collection.

This property is read-only. The default value is 0 for an initially empty collection.


For several common Silverlight elements, you can get the relevant collection and enumerate the child items of a parent object by accessing the "Children" collection of the parent object (Canvas.Children, GeometryGroup.Children, Storyboard.Children, TransformGroup.Children). Other commonly used collection properties are Path.Data, TextBlock.Inlines, and LinearGradientBrush.GradientStops.

Note   Using the Count property with an object that does not support a collection will raise a Silverlight runtime error.


The following JavaScript example shows how to use the Count property to enumerate the children of a parent Canvas object:

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

Collection, GeometryCollection, GradientStopCollection, Inlines, PathFigureCollection, PathSegmentCollection, StrokeCollection, StylusPointCollection, TransformCollection, TriggerCollection, VisualCollection

See Also

Referencing and Modifying Silverlight Objects

Community Additions