Present ListBox Items Bottom-to-Top

2019-02-12 23:23发布

问题:

I've searched for quite a while trying to find an answer to this without any results.

The default WPF Listbox adds items aligned at the top, and additional items below it. I'd like a listbox which presents the items in the opposite direction, so it adds items aligned to the bottom.

Example:

I'm sure there must be a simpler way that I've overlooked to do this without rewriting it all, but Google doesn't seem to have the answer for this one and I'm stumped.

Thanks.

回答1:

Change the ItemsPanel's layout:

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <VirtualizingStackPanel VerticalAlignment="Bottom"/>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>

This does what your image seems to imply, with the first item added still on top. If you want to reverse the order as well that would be a different issue.