Export (0) Print
Expand All

Clear

Silverlight

Removes all objects from the collection.

retval = object.Clear()

Type: Boolean

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

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.
myCanvas.children.clear();

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)
    {
        rootCanvas.children.remove(captionTextBlock);
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft