ItemsControl 可以对绑定的集合进行分组吗?
我试图确定是否有一种方法可以使用 ItemsControl 将 ItemsSource 中的项目分组到单独的 ItemsPanel 中。具体来说,我正在尝试创建一个视图,以便可以以网格类型的方式列出 8 个项目的集合,例如 UniformGrid,但结果均匀,而不是空单元格。
虽然源中包含 8 个项目的 UniformGrid 会产生如下结果:(
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++ - +++++++++ - ooooooooo -
-------------------------------------
最后一个单元格为空)
我试图产生如下结果:
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++++++++ - +++++++++++++++ -
-------------------------------------
如果我以编程方式将其分解,我可以通过像这样嵌套来轻松获得显示:
<StackPanel Orientation="Horizontal">
<UniformGrid>
item 1
item 2
item 3
</UniformGrid>
<UniformGrid>
item 4
item 5
item 6
</UniformGrid>
<UniformGrid>
item 7
item 8
</UniformGrid>
</StackPanel>
但我想通过 Xaml 来达到我想要的结果。
I'm trying to determine if there's a way to use an ItemsControl to group items in the ItemsSource into individual ItemsPanels. Specifically, I'm trying to create a view such that a collection of say, 8 items can be listed in grid-type fashion, like a UniformGrid, but with even results, and not empty cells.
While a UniformGrid with 8 items in the source would produce results like the following:
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++ - +++++++++ - ooooooooo -
-------------------------------------
(the last cell being empty)
I'm trying to produce results like so:
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++ - +++++++++ - +++++++++ -
-------------------------------------
- +++++++++++++++ - +++++++++++++++ -
-------------------------------------
If I programmatically break it up, I can get the display easily by nesting like so:
<StackPanel Orientation="Horizontal">
<UniformGrid>
item 1
item 2
item 3
</UniformGrid>
<UniformGrid>
item 4
item 5
item 6
</UniformGrid>
<UniformGrid>
item 7
item 8
</UniformGrid>
</StackPanel>
But I'd like to acheive the results I want just through Xaml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种方法,方法是在绑定到集合的 DataTemplate 中嵌套一个新的 ItemsControl,并使用 ValueConverter 将集合转换为数组的数组。
和值转换器:
I found the way to do it by nesting an new ItemsControl in the DataTemplate of the one bound to the collection, and using a ValueConverter to convert the collection into an array of arrays.
And the ValueConverter: