简体   繁体   中英

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 ?

So it was ease as 2 x 2 :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM