根据文档 ,经过过滤的CollectionView的计数应仅是通过过滤器的项目数。给出以下代码:
According to the documentation, the Count of a filtered CollectionView should only be the count of items that pass the filter. Given this code:
List<string> testList = new List<string>(); testList.Add("One"); testList.Add("Two"); testList.Add("Three"); testList.Add("1-One"); testList.Add("1-Two"); testList.Add("1-Three"); CollectionView testView = new CollectionView(testList); int testCount1 = testView.Count; testView.Filter = (i) => i.ToString().StartsWith("1-"); int testCount2 = testView.Count;因此,我希望testCount1为6,而testCount2为3。但是,两者均为6。如果我手动遍历CollectionView并计数项目,则得到3,但Count始终返回6。
I would therefore expect testCount1 to be 6, and testCount2 to be 3. However, both are 6. If I manually iterate through the CollectionView and count the items, I do get 3, but Count returns 6 always.
我尝试在CollectionView上调用Refresh,只是为了看看是否可以纠正结果,但是没有变化。文档是否有误? CollectionView中有错误吗?我是在做我看不见的错吗?
I've tried calling Refresh on the CollectionView, just to see if that would correct the result, but there was no change. Is the documentation wrong? Is there a bug in CollectionView? Am I doing something wrong that I just can't see?
推荐答案尝试
ICollectionView _cvs = CollectionViewSource.GetDefaultView(testList);而不是
CollectionView testView = new CollectionView(testList);更多推荐
筛选后的CollectionView计数错误
发布评论