I have several CollectionViewSource instances all used on the same ObservableCollection. I also have several controls that need to show filtered versions of the collection (hence the CollectionViewSources). The problem I'm having is that CollectionViewSource forces them to all have the same item selected. Is there some way to turn this off?
我有几个CollectionViewSource实例,它们都在同一个天文台中使用。我也有几个控件,需要显示收集的经过筛选的版本(因此是CollectionViewSources)。我遇到的问题是CollectionViewSource强制它们都选择了相同的项。有什么办法把它关掉吗?
Thanks, Jason Lewis
谢谢你,杰森·刘易斯
1 个解决方案
#1
0
If you use the method (im not sure about this but CollectionViewSource in xaml probably does)
如果您使用该方法(对此我不确定,但是xaml中的CollectionViewSource可能会)
CollectionViewSource.GetDefaultView(this.ItemsSource);
multiple times it will only return the same ICollectionView (if we are talking about the same collection bound multiple times), this means if you apply a filter to one it apllies to all, also as the collection view tracks the current item the current item will be syncronised between the different views.
多次这只会返回相同的ICollectionView(如果我们谈论的是同一收集绑定多次),这意味着如果一个过滤器适用于运用,也为集合视图跟踪当前项当前项将syncronised之间的不同的观点。
You can work around this by creating a CollectionView for each filter/selection you want to have by using
您可以通过为您希望使用的每个过滤器/选择创建一个集合视图来解决这个问题
new CollectionView(this.ItemsSource as IList);
there are a few types that implement ICollectionView, CollectionView and ListCollectionView do. in the above code i did not get the default view i created a new one, so its filering/sorting is unique.
有一些类型实现了ICollectionView、CollectionView和ListCollectionView。在上面的代码中,我没有得到我创建的默认视图,所以它的文件/排序是唯一的。
When you use items source wpf creates a collection view to wrap the collection, this collection view is the one that is returned in the GetDefaultView call, useful for every day situations but not the edge cases.
当您使用items source wpf创建一个集合视图来包装集合时,这个集合视图是GetDefaultView调用中返回的视图,对于日常情况有用,但是对于边缘情况没有用处。
here is a blog post from bea that explains it a bit better
这是来自bea的一篇博客文章,可以更好地解释这一点
#1
0
If you use the method (im not sure about this but CollectionViewSource in xaml probably does)
如果您使用该方法(对此我不确定,但是xaml中的CollectionViewSource可能会)
CollectionViewSource.GetDefaultView(this.ItemsSource);
multiple times it will only return the same ICollectionView (if we are talking about the same collection bound multiple times), this means if you apply a filter to one it apllies to all, also as the collection view tracks the current item the current item will be syncronised between the different views.
多次这只会返回相同的ICollectionView(如果我们谈论的是同一收集绑定多次),这意味着如果一个过滤器适用于运用,也为集合视图跟踪当前项当前项将syncronised之间的不同的观点。
You can work around this by creating a CollectionView for each filter/selection you want to have by using
您可以通过为您希望使用的每个过滤器/选择创建一个集合视图来解决这个问题
new CollectionView(this.ItemsSource as IList);
there are a few types that implement ICollectionView, CollectionView and ListCollectionView do. in the above code i did not get the default view i created a new one, so its filering/sorting is unique.
有一些类型实现了ICollectionView、CollectionView和ListCollectionView。在上面的代码中,我没有得到我创建的默认视图,所以它的文件/排序是唯一的。
When you use items source wpf creates a collection view to wrap the collection, this collection view is the one that is returned in the GetDefaultView call, useful for every day situations but not the edge cases.
当您使用items source wpf创建一个集合视图来包装集合时,这个集合视图是GetDefaultView调用中返回的视图,对于日常情况有用,但是对于边缘情况没有用处。
here is a blog post from bea that explains it a bit better
这是来自bea的一篇博客文章,可以更好地解释这一点