I recently posted a question onto CodeReview (CodeReview Question) and following their advice I am looking from moving from an ObservableCollection to an ICollectionView to a ListCollectionView instead as apparently a ListCollectionView has better filtering performance.
What I do at the moment is this;
Contracts = await ReturnContracts();
ContractsICollectionView = CollectionViewSource.GetDefaultView(Contracts);
DataContext = this;
Where Contracts is the ObservableCollection and ContractsICollectionView is the ICollectionView. When I use a ListCollectionView instead I get this error;
Cannot convert from ICollectionView to ListCollectionView.
Here is the definition of Contracts and ContractsListCollectionView;
public ObservableCollection<ContractModel> Contracts;
public ListCollectionView ContractsListCollectionView { get; private set; }
My question is how can I implement ListCollectionView and take advantage of its improved filtering?
Just declare ContractsListCollectionView like this:
public ICollectionView ContractsListCollectionView { get; private set; }
Alternatively, if you really need use ListCollectionView methods, and not just ICollectionView (note that ListCollectionView implements ICollectionView), then you need to make a cast:
ContractsICollectionView = (ListCollectionView) CollectionViewSource.GetDefaultView(Contracts);
Note that while for ObservableCollection CollectionViewSource.GetDefaultView indeed returns ListCollectionView - for other collection types it might not be the same and cast will fail. However since you are using it only with ObservableCollection - cast is fine.
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