RemoveAt Method
Removes the object at the specified index.
XAML |
Cannot use methods in XAML.
|
Scripting |
retval = object.RemoveAt(index)
|
Parameters
index | object The zero-based index of the object to remove. |
Return Value
object
A reference to the removed item from the collection if successful; otherwise, returns null.
Remarks
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. As soon as objects are removed from the Silverlight object hierarchy, they are no longer rendered.
Examples
The following JavaScript example shows how to remove 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); |
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.
JavaScript |
---|
function removeCaption(rootCanvas) { // Retrieve the TextBlock object. var captionTextBlock = rootCanvas.findName("myCaption"); if (captionTextBlock != null) { rootCanvas.children.remove(captionTextBlock); } } |
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 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