问题
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