Export (0) Print
Expand All

Remove Method

Removes the specified object from the collection.

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

Parameters

value

object

The object to remove from the collection.

Return Value

Boolean

true if value was removed from the collection; otherwise, false.

Remarks

The Remove method removes a child object from the parent collection by referencing the object's x:Name attribute value. As soon as objects are removed from the Silverlight object hierarchy, they are no longer rendered. When you remove an object using the Remove or RemoveAt methods, you are disconnecting the object from the Silverlight object hierarchy. The disconnected object is now a XAML fragment that can be connected back to the object hierarchy using the Add method. The following illustrations show the concept of disconnecting objects from the Silverlight object hierarchy.

Removing an object from the Silverlight object hierachy

Removing an object from the Silverlight object hierachy

Disconnected XAML fragment and Silverlight object hierarchy

Disconnected XAML fragment and Silverlight object hierarchy

Examples

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

The RemoveAt method removes a child object at a specified index value in the parent's collection. This means the child object does not require an x:Name attribute value. The following JavaScript example removes the first object from a parent Canvas object by using the RemoveAt method:

JavaScript
// Remove the first child object from the parent collection.
myCanvas.children.removeAt(0);

You can remove all objects in a collection by using the Clear method, which is equivalent to using the RemoveAt method for each item in the collection. 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();

Applies To

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

See Also

Referencing and Modifying Silverlight Objects
Clear
RemoveAt

Community Additions

Show:
© 2014 Microsoft