Compartir a través de


Insert

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

Inserts an object into the collection at the specified index.

object.Insert(index, value)

Arguments

index

integer

The index at which the object should be inserted.

value

object

The object to insert into the collection.

Managed Equivalent

Each collection type potentially implements this differently.

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.

Example

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

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

See Also

Reference

Add