bone_appettit
bone_appettit

Reputation: 125

How to add a child element to the top of StackPanel?

I'm trying to add some child elements of StackPanel on top.

There is a code:

<StackPanel Orientation="Vertical">
  <Border Background="SkyBlue">
    <TextBlock>Stacked Item #1</TextBlock>
  </Border>
  <Border Background="CadetBlue">
    <TextBlock>Stacked Item #2</TextBlock>
  </Border>
  <Border Background="LightGoldenRodYellow">
    <TextBlock >Stacked Item #3</TextBlock>
  </Border>

and there is a image:

enter image description here

I want the child elements to be added up instead of down, how can I do this?

Like this:
Stacked Item 3
Stacked Item 2
Stacked Item 1

Upvotes: 1

Views: 1479

Answers (1)

bone_appettit
bone_appettit

Reputation: 125

I found the solution.

StackPanel.Children.Insert(0, UIElement)

This will insert child element at the head of the list.

Upvotes: 2

Related Questions