RemoveAt

Silverlight

Removes the object at the specified index from a collection.

retval = object.RemoveAt(index)

index

object

The zero-based index of the object to remove.

Type: object

A reference to the item removed from the collection if successful; otherwise, returns null.

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

The RemoveAt method removes a child object at a specified index value from the parent's collection. This means that the child object does not require an x:Name attribute value. As soon as objects are removed from the Silverlight object hierarchy, they are no longer rendered.

The following JavaScript example shows how to remove 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);

The Remove method removes a child object from the parent's collection by referencing the object's x:Name / 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.

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

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

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 removes all items from a collection by using the Clear method.

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

Community Additions

ADD
Show: