过滤的CollectionView提供错误的计数

根据文档,过滤的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("");
int testCount2 = testView.Count;
因此我希望testCount1为6,testCount2为3.但是,两者都是6.如果我手动迭代CollectionView并计算项目,我会得到3,但Count总是返回6。 我试过在CollectionView上调用Refresh,只是为了看看是否会纠正结果,但没有变化。文档错了吗? CollectionView中有错误吗?我做错了什么,我看不到?     
已邀请:
尝试
ICollectionView _cvs = CollectionViewSource.GetDefaultView(testList);
代替
CollectionView testView = new CollectionView(testList);    
    
如果切换到ListCollectionView,它按预期工作:
CollectionView testView = new ListCollectionView(testList);
int testCount1 = testView.Count;
testView.Filter = (i) => i.ToString().StartsWith("");
int testCount2 = testView.Count;
这似乎适用于CollectionView,所以这肯定指向一个错误:
CollectionView testView = new CollectionView(this.GetTestStrings());

private IEnumerable<string> GetTestStrings() {
    yield return "One";
    yield return "Two";
    yield return "Three";
    yield return "1-One";
    yield return "1-Two";
    yield return "1-Three";
}
    
似乎有一个错误,我检查反射器可能是如果你尝试调用“刷新”,应该给你正确的计数。根据文档,他们说你不需要调用Refresh,因为设置过滤器会自动刷新它,但我认为它没有发生,因为他们还提到他们从最后一次更改中缓存count的值。 如果在添加项目之前设置过滤器,它将工作得很好。或者您必须致电刷新。     

要回复问题请先登录注册