Count

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the number of items contained in a collection.

value = object.Count

Property Value

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.

Managed Equivalent

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

Remarks

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.

NoteNote:

Using the Count property with an object that does not support a collection will raise a Silverlight run-time error.

Example

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