WinUI-Gallery icon indicating copy to clipboard operation
WinUI-Gallery copied to clipboard

How to do all the things to a Collection - Sorting, Filtering, Updating, Grouping

Open michael-hawker opened this issue 1 year ago • 5 comments

Issue type

sample request

Which version of the app?

WinUI 3 Gallery

Description

Especially for the new ItemsView, but even just for ListView, there's not a full-fledged example anywhere of how to take a large collection of items and performantly sort, filter, update, and group them within a UI container.

In WPF, CollectionViewSource did a lot of heavy lifting here, but there's a gap for the platform still on this: https://github.com/microsoft/microsoft-ui-xaml/issues/4307

So, even more so, a sample that shows how to do this that's production ready would be appreciated.

The doc on filtering that do exist, seems woefully inefficient or error-prone compared to the simplicity of setting the Filter from WPF days: https://learn.microsoft.com/dotnet/desktop/wpf/data/how-to-filter-data-in-a-view

Screenshots

No response

Windows version

No response

Additional context

No response

michael-hawker avatar Sep 19 '24 21:09 michael-hawker

This demo app might help. 🙂

https://github.com/user-attachments/assets/5f796f6b-0a9d-4357-bb3f-22a39ed2363b

AndrewKeepCoding avatar Oct 19 '24 09:10 AndrewKeepCoding

Here's the repo.

https://github.com/AndrewKeepCoding/CollectionOperationsDemo

AndrewKeepCoding avatar Oct 19 '24 09:10 AndrewKeepCoding

I'm not sure if the ItemsView is a good option for grouping. The selection feature is not what you would expect. 🤔

AndrewKeepCoding avatar Oct 19 '24 09:10 AndrewKeepCoding

There's the ObservableGroupedCollections in the .NET Community Toolkit as well. You can next ItemsRepeaters as well similarly to how you've done as well. I played around with that long ago, just made that experimental repo public for posterity: https://github.com/michael-hawker/ItemsRepeaterTests

@AndrewKeepCoding was just thinking about your comment. I don't have the full context, but I imagine you only want the ItemsView to be on the outer main control, and then still use an ItemsRepeater internally for the inner items? Or maybe vice-versa, as you want the containers for selection on the individual items vs. on the groups themselves.

michael-hawker avatar Mar 31 '25 21:03 michael-hawker

@michael-hawker Looking at now, you can easily change the selection behaviors (outer and inner) using the SelectionMode.

AndrewKeepCoding avatar Apr 01 '25 00:04 AndrewKeepCoding