I have ICollectionView
private ICollectionView _snapshotList;
public ICollectionView SnapshotList {
get { return _snapshotList; }
}
which im setting in ViewModel constructor, where this.smapshotListModel.SnapshotItems returns ObservableCollection
_snapshotList = CollectionViewSource.GetDefaultView(this.snapshotListModel.SnapshotItems);
_snapshotList.Filter = ErrorMsgFilter;
_snapshotList.CollectionChanged += OnCollectionChanged;
And later in collectionChanged event im trying to get count of items in this collection,
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
this.ItemCount = _snapshotList.Count();
}
But its throwing error, that there is no Definition for Count method.
Try like this;
_snapshotList.Cast<object>().Count();
ICollectionView implements IEnumarable but it doesn't implement IEnumerable<TSource> like List<TSource>, HashSet<TSource> etc. So, ICollectionView doesn't have a generic type and we have to cast it to IEnumerable<object> once to enable Count() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With