棘手的 WPF 样式问题 - 你能做到吗?
我有一个可观察的项目集合,其中每个项目都有一个名称和一个“组名称”(都是字符串)。
棘手的部分是,在 XAML 中,我需要设置此集合的样式,以便具有相同组名称的所有项目彼此相邻列出,并且组名称显示在顶部。
我为组名称的布局以及所显示的每个项目的布局设计了用户控件。 我已经使用过 ItemsControl,但不知道如何设计它的样式,以便具有相同组的项目以某种方式“合并”到使用通用 ItemControl 用户控件作为其源的同一个 ItemsControl 中,组名称显示在顶部。
我确实通过使用“组”集合来完成此工作,每个组内都有一个项目集合,因为绑定工作得很好。 但是,我没有考虑到每个项目可能属于多个组(将一个人视为“工作朋友”和“同事”组,因此需要重复)。
非常感谢任何建议或解决方案:)
I have an observable collection of items, where each item has a name and a "group name" (both strings).
The tricky part is, in XAML, I need to style this collection such that all items with the same group name are listed next to each other, and the group name is shown at the top.
I have designed user controls for the layout of the group name, as well as the layout of each item being displayed. I have played around with ItemsControl but have no idea how to style it so that items with the same group are somehow "merged" into the same ItemsControl that uses the generic ItemControl user control as its source, with the group name displayed on top.
I did have this working by using a collection of "groups", with a collection of items inside each group, because the bindings work perfectly. However, I did not take into account that each item may be in more than one group (think of a person as being in a "work friends" as well as "colleagues" group, so it needs to be duplicated).
Any advice or solutions are much appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,使用
CollectionViewSource
对项目进行排序:然后从您的
ItemsControl
(或其他)绑定到它:First, use a
CollectionViewSource
to sort the items:Then bind to it from your
ItemsControl
(or whatever):