【发布时间】:2011-08-03 04:24:21
【问题描述】:
根据documentation,过滤后的 CollectionView 的 Count 应该只是通过过滤器的项目的计数。鉴于此代码:
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。
我尝试在 CollectionView 上调用 Refresh,只是想看看这是否会纠正结果,但没有任何变化。文档有错吗? CollectionView 中是否有错误?我是不是做错了什么我看不到的事情?
【问题讨论】:
-
这必须有效,但我不确定:testview.OfType
标签: wpf collectionview