Search code examples
c#wpfstackpanel

How to display newly added element at the top of StackPanel in WPF?


I add UserControl to StackPanel like this

public void AddEvent(UserControl uc)
{
    stackPanelMain.Children.Add(uc);
}

But I would like to reorder them and display the last added element at the top.

Is there a way to do it without let's say some Dictionary<DateTime, UserControl> and foreach to populate Children property of stackPanel?


Solution

  • So it was ease as 2 x 2 :)

    public void AddEvent(UserControl uc)
    {
         stackPanelMain.Children.Insert(0, uc);
    }