Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms - Equivalent of CollectionViewSource

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?

like image 426
Christian Findlay Avatar asked Feb 11 '18 07:02

Christian Findlay


People also ask

What is the difference between ListView and CollectionView in Xamarin forms?

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.

What is WPF CollectionViewSource?

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.

How do I use Xamarin community toolkit?

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.


2 Answers

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.

like image 182
Christian Findlay Avatar answered Sep 23 '22 00:09

Christian Findlay


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/

like image 28
r2d2rigo Avatar answered Sep 20 '22 00:09

r2d2rigo