In WPF and other XAML based technologies there was a class called CollectionViewSource. It was useful because rather than filtering and sorting inline etc. one would put a layer over the top of the actual collection, and only expose the sorted/filtered view to the UI. This meant that the model would stay clean while the UI could sort or filter. Is there an equivalent in Xamarin Forms?
The List<> class has a sort method which would be perfect. But, List<> doesn't implement INotifyCollectionChanged. Is there a List that implements INotifyCollectionChanged and a Sort method?
While the CollectionView and ListView APIs are similar, there are some notable differences: CollectionView has a flexible layout model, which allows data to be presented vertically or horizontally, in a list or a grid. CollectionView supports single and multiple selection. CollectionView has no concept of cells.
CollectionViewSource is a proxy for a CollectionView class, or a class derived from CollectionView. CollectionViewSource enables XAML code to set the commonly used CollectionView properties, passing these settings to the underlying view.
Setup Xamarin Community ToolkitOpen an existing project, or create a new project using the Blank Forms App template. In the Solution Explorer panel, right click on your project name and select Manage NuGet Packages. Search for Xamarin. CommunityToolkit, and choose the desired NuGet Package from the list.
There is no equivalent. The feature has been requested here:
https://github.com/xamarin/Xamarin.Forms/issues/2193
Please comment your thoughts on the Github issue so that the Xamarin Forms team knows that this is important.
This is one of the features I have always found lacking in Xamarin Forms and, while a few issues were raised and requests made, it is still missing from XF as of version 4.8
I went ahead and made a partial port (only supports filtering and sorting as of now) of WPF's CollectionView which can be found at
https://www.nuget.org/packages/CollectionViewSource.Forms/
It is open source, so any issues or improvements can be filed at
https://github.com/rotorsoft-ltd/CollectionViewSource.Forms/
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