【发布时间】:2019-05-30 00:27:25
【问题描述】:
我正在尝试在我的 WPF 应用程序的一个视图中的 ItemsControl 中设置一个列表。
问题是我想要在控件中显示的我的项目的其他顺序。 主要,ItemsControl 从左到右和从上到下显示项目:
1 2 3 4 5 6
7 8 9 10 11 12
但是,我想以其他方式显示我的项目 - 从右上到左下 - 像这样:
11 9 7 5 3 1
12 10 8 6 4 2
我当前的 ItemsControl 是:
Grid.Column="1"
BorderThickness="1"
BorderBrush="{DynamicResource WindowTitleColorBrush}">
<ItemsControl ItemsSource="{Binding Truck.Containers}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="2" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Border>
我不能只是通过在视图模型中降序来重新排序我的列表,因为它将以 12 开始并以 1 而不是 11 - 2 结束。 还有其他方法可以按我想要的顺序显示我的列表吗?
【问题讨论】:
-
最好的方法是在 ViewModel 中按照您想要的方式对项目进行排序。
-
解决方案的一半在 UniformGrid 上的
FlowDirection="RightToLeft"中。另一半可以通过生成派生类来解决,如here 所述