我有ICollectionView
private ICollectionView _snapshotList;
public ICollectionView SnapshotList {
get { return _snapshotList; }
}在ViewModel构造函数中的哪个im设置,其中this.smapshotListModel.SnapshotItems返回ObservableCollection
_snapshotList = CollectionViewSource.GetDefaultView(this.snapshotListModel.SnapshotItems);
_snapshotList.Filter = ErrorMsgFilter;
_snapshotList.CollectionChanged += OnCollectionChanged;稍后在collectionChanged事件中,我尝试获取此集合中的项的计数,
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
this.ItemCount = _snapshotList.Count();
}但它抛出的错误是,没有Count方法的定义。
发布于 2017-12-17 18:38:11
试着这样做;
_snapshotList.Cast<object>().Count();ICollectionView实现了IEnumarable,但它没有像List<TSource>、HashSet<TSource>等那样实现IEnumerable<TSource>。因此,ICollectionView没有泛型类型,我们必须将其强制转换为IEnumerable<object>一次才能启用Count()方法。
https://stackoverflow.com/questions/47854184
复制相似问题