Export (0) Print
Expand All

Clear Method

Removes all objects from the collection.

XAML
Cannot use methods in XAML.
Scripting
retval = object.Clear()

Return Value

Boolean

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

Remarks

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

Examples

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

JavaScript
// Remove all child objects from the parent collection.
myCanvas.children.clear();

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

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

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

    if (captionTextBlock != null)
    {
        rootCanvas.children.remove(captionTextBlock);
    }
}

Applies To

ColorKeyFrameCollection, DoubleKeyFrameCollection, GradientStopCollection, Inlines, PathFigureCollection, PathSegmentCollection, PointKeyFrameCollection, StrokeCollection, StylusPointCollection, TriggerActionCollection, TriggerCollection, VisualCollection

See Also

Referencing and Modifying Silverlight Objects

Community Additions

Show:
© 2015 Microsoft