在 ListView 中对组进行分组
我有一个项目集合,每个项目都位于某些组中。 我在 WPF 列表视图中显示集合,并希望按组进行分组,但这是不可能的,因为我有一个 IEnumerable :-)。并且一行必须不仅出现一次。
有人知道我该如何解决这个问题吗?
I have a collection of items, and every item is in some groups.
I show the collection in a WPF Listview and want to group by the groups, but that is not possible becuase i have a IEnumerable :-). And a row has to show up not only once.
Does anybody have an idea how i can solve this problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
波浪屿的海角声2025-01-07 22:05:11
最好使用 TreeView 和 HierarchicalDataTemplate 显示您的分组级别数据结构。
我不知道你的数据结构到底是什么样的。如果您已经扁平化数据,您可能需要将这种数据结构更改
public class Item
{
public string Group { get; set; } // A prop you want the grouping on
public string AnotherItemProp { get; set; }
}
public IEnumerable<Item> Items // used as your list source somewhere
为:
public class Group
{
public string AnotherGroupProp { get; set; } // grouping value from flattened
public IEnumerable<Item> Items { get; set; }
}
public class Item
{
public string AnotherItemProp { get; set; }
}
public IEnumerable<Group> Groups { get; set; } // Used by treeview
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以将 DataTemplate 用于内部项目,并在内部数据模板内使用另一个列表视图来显示该组项目。
You can use DataTemplate for the inner item and inside the inner data template another Listview can be used to display that group items.