UIElementCollection.Insert(Int32, UIElement) Method

Definition

Inserts an element into a UIElementCollection at the specified index position.

C#
public virtual void Insert(int index, System.Windows.UIElement element);

Parameters

index
Int32

The index position where you want to insert the element.

element
UIElement

The element to insert into the UIElementCollection.

Examples

The following example uses the Insert method to insert child content at a specified index position.

C#
void InsertControls(object sender, RoutedEventArgs e)
{
    btn2 = new Button();
    btn2.Content = "Inserted Button";
    sp1.Children.Insert(1, btn2);
}

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10