绑定到CollectionViewSource问题 [英] Binding to a CollectionViewSource Question

查看:181
本文介绍了绑定到CollectionViewSource问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是这样的:



我有2 ListBox:



一个绑定到一个集合所谓的照片类型的照片,另一个绑定到一个CollectionViewSource绑定到相同的照片集合。



listBox1 - >照片(这里listBox1绑定到默认照片的CollectionView,当然不是直接照片。)



ListBox2 - > cvs - >照片



两个集合(默认和我的CVS)都有一个过滤器,可以将它们显示的项目从8个项目减少到5个。



现在我有2个标签。一个被绑定到照片对象的Count属性,另一个绑定到Count属性,其中源是cvs(我的CollectionViewSource)对象。



第一个标签显示数字8,正如我所见,这是因为照片数量保持8,即使我是过滤掉它的默认CollectionViewSource。



第二个标签显示数字我所学到的关于绑定到cvs的是WPF将来自cvs的源对象展开,Path = Count与底层对象相关,它是照片和这个数字应该是8。



有人可以解释一下我在哪里穿?



谢谢!

解决方案

绑定不会绑定到源集合,而是绑定视图。集合视图还具有 计数 属性,返回(过滤)视图而不是原始集合中的项目数。



(您可以使用调试器查看 查看 属性。 aspxrel =nofollow> CollectionViewSource 通常是一个对象,它是 CollectionView 或其子类之一,绑定将隐含地绑定到 View.Count



要绑定到原始计数,使用路径 SourceCollectio n.Count


My issue goes like that:

I have 2 ListBox:

one is bound to a collection called photos of type Photos and the other is bound to a CollectionViewSource which is bound to the same photos collection.

listBox1 -> photos (here the listBox1 is bound to the Default CollectionView of photos, of course and not directly to photos.)

ListBox2 -> cvs -> photos

both collection (the default one and my CVS) having a filter that reduce the items they show from 8 items to 5 items.

now i have 2 labels. one is bound to the Count property of the photos object and the other one is bound to the Count property where the source is the cvs (my CollectionViewSource) object.

the first label show the number 8 and as i see it, it is because the Count of photos stays 8 even though i am filterring it's default CollectionViewSource.

the second label shows the number 5.

what i learnt about binding to a cvs is that WPF unwrapps the source object from the cvs and the Path=Count is relevant to the underlying object which is photos and the number here should be 8 also.

does someone can explain me where i am worng?

thanks!

解决方案

The binding will not bind to the source collection but the view. The collection view also has a Count property which returns the number of items in the (filtered) view rather than in the original collection.

(You can use the debugger to see that the View property of the CollectionViewSource normally will be an object which is an instance of CollectionView or one of its subclasses. The binding will implicitly bind to View.Count)

To bind to the original count use the path SourceCollection.Count.

这篇关于绑定到CollectionViewSource问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆