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

Removes all objects from the collection.

retval = object.Clear()

Return Value

Type: Boolean

true if all the objects were removed from the collection; otherwise, false.

Managed Equivalent

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


The Clear method is equivalent to using the RemoveAt method for each item in the collection.


The following JavaScript example shows how to remove all items from a collection by using the Clear method.

// Remove all child objects from the parent collection.

The Remove method enables you to remove a specific child object from the parent collection by referencing the object's x:Name attribute value.

The following JavaScript example shows how to remove a TextBlock object from its parent Canvas object by using the Remove method on the object's collection of child objects.

function removeCaption(rootCanvas)
    // Retrieve the TextBlock object.
    var captionTextBlock = rootCanvas.findName("myCaption");

    if (captionTextBlock != null)