using-avalonia-collectionview

Implements collection filtering, sorting, and grouping in AvaloniaUI using DataGridCollectionView and ReactiveUI.

Updated Nov 22, 2023
One-click install
npx skills add https://github.com/parksanghoon-sys/TestCode --skill using-avalonia-collectionview-parksanghoon-sys
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: using-avalonia-collectionview
Source: https://github.com/parksanghoon-sys/TestCode/tree/main/src/Modbus/.agents/skills/using-avalonia-collectionview
Command: npx skills add https://github.com/parksanghoon-sys/TestCode --skill using-avalonia-collectionview-parksanghoon-sys

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires Avalonia.Controls.DataGrid, ReactiveUI.Avalonia, DynamicData, CommunityToolkit.Mvvm, Microsoft.Extensions.Hosting.

What problem does it solve? AvaloniaUI does not support WPF's CollectionViewSource, leaving developers without a familiar way to filter, sort, and group collections in MVVM applications. This Skill provides working alternatives and a complete sample project structure. ## Core Features & Use Cases - DataGridCollectionView Approach: Wraps an ObservableCollection in a service layer that returns filtered IEnumerable views, keeping ViewModels free of Avalonia references. - ReactiveUI Alternative: Uses DynamicData SourceList with Filter, Sort, and Bind operators for reactive collection pipelines. - Layered Sample Project: Includes a four-project template (Core, ViewModels, AvaloniaServices, App) demonstrating dependency injection with Microsoft.Extensions.Hosting and CommunityToolkit.Mvvm. - Use Case: When migrating a WPF app to AvaloniaUI, replace CollectionViewSource-based filtering with a MemberCollectionService that exposes filtered DataGridCollectionView instances to a pure-BCL ViewModel. ## Quick Start Show me how to filter and sort an ObservableCollection in an AvaloniaUI MVVM app without using WPF's CollectionViewSource.

Frequently Asked Questions about using-avalonia-collectionview

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I filter a collection in AvaloniaUI without CollectionViewSource?▼

Use DataGridCollectionView from the Avalonia.Controls.DataGrid NuGet package. Wrap your ObservableCollection in a DataGridCollectionView and set its Filter property to a predicate, then expose it as IEnumerable to your ViewModel.

DataGridCollectionView vs ReactiveUI DynamicData for AvaloniaUI filtering?▼

DataGridCollectionView works well for DataGrid scenarios with simple filter predicates. ReactiveUI with DynamicData suits reactive pipelines, offering Connect, Filter, Sort, and Bind operators that produce ReadOnlyObservableCollection outputs.

Does AvaloniaUI support WPF's CollectionViewSource?▼

No, AvaloniaUI does not support WPF's CollectionViewSource. The recommended alternatives are DataGridCollectionView from the DataGrid package or ReactiveUI with DynamicData for filtering, sorting, and grouping collections.

Can my ViewModel avoid referencing Avalonia assemblies when using DataGridCollectionView?▼

Yes. Place DataGridCollectionView creation in an Avalonia service layer and return it as IEnumerable. The ViewModel then depends only on pure BCL types and a service interface, keeping it free of Avalonia references.

How do I sort a collection with DynamicData in AvaloniaUI?▼

Call Connect on a SourceList, then chain Sort with SortExpressionComparer, for example SortExpressionComparer<Member>.Ascending(m => m.Name), followed by Bind to materialize results into a ReadOnlyObservableCollection.