根据documentation,已过滤的CollectionView的计数应该只是通过过滤器的项目的计数。鉴于此代码:已过滤的CollectionView给出错误计数
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上调用刷新,只是为了看看是否会纠正结果,但没有改变。文档是否错误? CollectionView中有错误吗?我做错了什么,我只是看不到?
这必须工作,但我不知道:testview.OfType