Remove

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

Removes the specified object from a collection.

retval = object.Remove(value)

Arguments

value

object

The object to remove from the collection.

Return Value

Type: Boolean

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

Managed Equivalent

Each managed collection type potentially implements this method differently.

Remarks

The Remove method removes a child object from a 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, but they still exist as objects. You could choose to re-add the object to the same collection, or to a different compatible collection. You could also deliberately set the object to null if you wanted to truly delete the object, but you should only do this for objects that are no longer part of any object tree by being part of a collection.

Example

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.

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 that 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.

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

You can remove all objects from 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 remove all items from a collection by using the Clear method.

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

See Also

Reference