合并两个 ObservableCollections
我有两个可观察集合,需要将它们合并为一个集合。
出现这种情况是因为我有两种方法, getTasks(staffID) 返回 ObservableCollection , getTasks(teamID) 选择人员并撤回人员任务。
对于团队,我将有多个小的 observableCollections,我只想合并它们。
I have two Observable Collections that I need to merge into one collection.
This arises because I have two methods, getTasks(staffID) which returns an ObservableCollection and getTasks(teamID) which selects the staff and pulls back the staff tasks.
For the teams I will have multiple small observableCollections, I just want to merge them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
Concat 或 Union,但结果是 IEnumerable,因此需要将其转换回 ObservableCollection:
This is what worked for me:
Concat or Union, but the result is a IEnumerable, so it needs to be converted back into an ObservableCollection:
我在另一个上找到了对 CompositeCollection 的引用SO文章: Merged ObservableCollection
由于您想要执行 Concat/Union,这似乎正是这样做的。可惜它不是强类型的。
I found a reference to CompositeCollection on another SO article: Merged ObservableCollection
Since you're looking to do a Concat/Union, this seems to do exactly that. Too bad it's not strongly typed.
我采纳了 volkerK 的建议,然后转到:
http: //msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx
塔
I went with volkerK's suggestion and then moved to:
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx
Ta