How to set items order in StackPanel

梦想的初衷 提交于 2019-12-11 11:15:39

问题


I have a List of string. e.g. "abc", "pqr", "xyz" in this order. A StackPanel is data bound to this list. I want to display the list in a StackPanel vertically but in reverse order from top to bottom

"xyz"
"pqr"
"abc"

Is there a way to do this in xaml or do I have to reorder my list?


回答1:


Yes and No, the StackPanel will display them in the order in which they are enumerated. So you have a couple of options as I see it:

1) Re-order your list

2) Change your binding, or apply a IValueConverter that does the re-order on the fly. This of course requires coding the converter, but once it's written you can re-use it in your XAML as required without having to modify individual windows, code-behinds, etc.




回答2:


This is very hackish, but seems to work. Set the stackpanel's layout transform to rotate 180. Then each child's layout transform also to 180.

<StackPanel Name="pnlLayers">
<StackPanel.LayoutTransform>
    <RotateTransform Angle="180"/>
</StackPanel.LayoutTransform>

(in my case, I had a custom user control as the row)

<UserControl.LayoutTransform>
    <RotateTransform Angle="180"/>
</UserControl.LayoutTransform>


来源:https://stackoverflow.com/questions/7475629/how-to-set-items-order-in-stackpanel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!