Question: I need to create a XAML `textbox` immediately after another `textbox` using code-behind. Maybe something like this:

Before

```
<StackPanel>
    <TextBox Name="TextBox1"/>
    <TextBox Name="TextBox2"/>
    <TextBox Name="TextBox3"/>
</StackPanel>

```

After

```
<StackPanel>
    <TextBox Name="TextBox1"/>
    <TextBox Name="TextBox2"/>
    <TextBox Name="InsertedTextBox"/> <!--This textbox was inserted after 'TextBox2'-->
    <TextBox Name="TextBox3"/>
</StackPanel>

```

I have the name of the `textbox` I wish to insert the other `textbox` after. May I know how I can insert a `textbox` after another `textbox` which I know the name of?

Note: I am programming for Universal Windows.

Thanks in advance.

Answer: 
You need to name the `StackPanel` to reference it in code, and you need the index of the preceding `TextBox`:

```
var index = this.stackPanel1.Children.IndexOf(TextBox2);
this.stackPanel1.Children.Insert(index + 1, new TextBox { Name = "InsertedTextBox" });

```
You could try this, note I've given the `StackPanel` a name.

```
// Where 2 is the index.
this.StackPanel1.Children.Insert(2, new TextBox());

```