Insert Method

Inserts an object into the collection at the specified index.

XAML
Cannot use methods in XAML.
Scripting
object.Insert(index, value)

Parameters

index

integer

The index at which the object should be inserted.

value

object

The object to insert into the collection.

Remarks

When you use the Insert method, you add the object to a specified index in the parent object's collection. Existing objects are shifted to make room for the new inserted object.

Examples

The following JavaScript example shows an object inserted into the beginning of a collection that contains three existing Rectangle objects.

JavaScript
// Insert an overlapping Rectangle object.
function InsertItem(rootCanvas)
{
    var plugin = rootCanvas.getHost();
    var xamlFragment = '<Rectangle Fill="Black" Canvas.Top="0" Canvas.Left="0" Height="100" Width="100" />';
    var rectangle_4 = plugin.content.createFromXaml(xamlFragment);
    rootCanvas.children.insert(0, rectangle_4);
}

The following illustration shows the display result of the previous JavaScript example. Notice that the rendering of the inserted object. Because the inserted object is the first object in the collection, it is overlaid by all of its siblings.

Z-order of an inserted object into the collection

Z-order of an inserted object into the collection

Applies To

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

See Also

Referencing and Modifying Silverlight Objects
Add