CollectionViewSource
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
It would be nice if MAUI offered the same functionality as the CollectionViewSource object for WPF:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.data.collectionviewsource?view=windowsdesktop-6.0
### Public API Changes
```
public void StakeholdersDefaultViewSort(ObservableCollection stakeholders, string propertyName)
{
// check input
ICollectionView icv = CollectionViewSource.GetDefaultView(stakeholders);
if (icv is null) return;
// if no property name, sort by default but don't flip
bool flip = (!string.IsNullOrEmpty(propertyName));
// set default direction based on property
ListSortDirection lsd;
switch (propertyName)
{
case nameof(Stakeholder.Name):
lsd = ListSortDirection.Ascending;
break;
case nameof(Stakeholder.Engagement):
lsd = ListSortDirection.Ascending;
break;
default:
propertyName = nameof(Stakeholder.Name);
lsd = ListSortDirection.Ascending;
break;
}
// if previously sorted on this property, flip it
if (icv.SortDescriptions.Count > 0 && icv.SortDescriptions[0].PropertyName == propertyName && flip)
lsd = (icv.SortDescriptions[0].Direction == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending;
// clear and sort the view
using (icv.DeferRefresh())
{
icv.SortDescriptions.Clear();
icv.SortDescriptions.Add(new SortDescription(propertyName, lsd));
}
}
```
### Intended Use-Case
It's often the case that I need multiple views of the same data collections (e.g. different sortings, grouping, or filtering) without modifying the underlying collection. CollectionViewSource provides this functionality. Each ICollectionView of the data created can be used to display the same underlying data differently to the user, in different views on the UI.
Contributor guide
Research direction
Start by comparing the linked WPF CollectionViewSource API with MAUI's existing collection-view capabilities. Define how multiple views should provide independent sorting, grouping, or filtering while leaving the underlying collection unchanged; the feature is done when that intended use case is supported without modifying the source data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100