Gets the number of items contained in a collection.

value = object.Count

Type: integer

The number of items contained in a collection.

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

Each collection type potentially implements this differently. The most common equivalent for Silverlight programming is PresentationFrameworkCollection<T>.Count.

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.


Using the Count property with an object that does not support a collection will raise a Silverlight run-time 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());

Community Additions