问题描述
有一大堆的的ObservableCollection< MeClass>结果
,并要求将它们全部组合成另一个的ObservableCollection< MeClass> AllResults
这样我就可以在列表视图中显示它
。
Have a bunch of ObservableCollection<MeClass> Result
and require to combine them all into another ObservableCollection<MeClass> AllResults
so I can display it in a listview
.
只是不知道如何将它们结合起来的。
Just not sure how to combine them all in one.
我创建了一个新的类来他们都结合起来,但不知道他们将如何得到更新后,我得到的名单,一旦...所以真的不知道该走的方向。
I Created a new class to combine them all but not sure how they will get updated after I got the list once... So not really sure which direction to take.
我知道 INotifyPropertyChanged的
我只是不知道如何把它们都结合起来,并不断更新的一切都变了。
I know about INotifyPropertyChanged
I'm just not sure how to combine them all and keep updating as everything changes.
推荐答案
.NET有一个<$c$c>CompositeCollection$c$c>这可以让你把多个集合作为一个单一的集合。它实现了 INotifyCollectionChanged
,所以只要你的内心集合实施 INotifyCollectionChanged
,以及(在你的情况下,他们当然喜欢) ,您的绑定应该没有任何问题。
.NET has a CompositeCollection
that allows you to treat multiple collections as a single collection. It implements INotifyCollectionChanged
, so as long as your inner collections implement INotifyCollectionChanged
as well (which in your case they certainly do), your bindings should work without any problems.
用例:
CompositeCollection cc = new CompositeCollection();
CollectionContainer container1 = new CollectionContainer() { Collection = Result1 }
CollectionContainer container2 = new CollectionContainer() { Collection = Result2 }
cc.Add(container1);
cc.Add(container2);
这篇关于多个ObservableCollections绑定到一个的ObservableCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!