You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: components/Collections/samples/AdvancedCollectionView.md
+7-54Lines changed: 7 additions & 54 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
title: AdvancedCollectionView
3
3
author: nmetulev
4
-
description: The AdvancedCollectionView is a collection view implementation that support filtering, sorting and incremental loading. It's meant to be used in a viewmodel.
description: The AdvancedCollectionView is a collection view implementation that support filtering, sorting and incremental loading. It's meant to be used in a view or viewmodel.
In your viewmodel instead of having a public [IEnumerable](https://learn.microsoft.com/dotnet/core/api/system.collections.generic.ienumerable-1) of some sort to be bound to an eg. [Listview](https://learn.microsoft.com/uwp/api/Windows.UI.Xaml.Controls.ListView), create a public AdvancedCollectionView and pass your list in the constructor to it. If you've done that you can use the many useful features it provides:
17
+
In your view or viewmodel instead of having a public [IEnumerable](https://learn.microsoft.com/dotnet/core/api/system.collections.generic.ienumerable-1) of some sort to be bound to an eg. [Listview](https://learn.microsoft.com/uwp/api/Windows.UI.Xaml.Controls.ListView), create a public AdvancedCollectionView and pass your list in the constructor to it. If you've done that you can use the many useful features it provides:
20
18
21
19
* sorting your list using the `SortDirection` helper: specify any number of property names to sort on with the direction desired
22
20
* filtering your list using a [Predicate](https://learn.microsoft.com/dotnet/core/api/system.predicate-1): this will automatically filter your list only to the items that pass the check by the predicate provided
23
21
* deferring notifications using the `NotificationDeferrer` helper: with a convenient _using_ pattern you can increase performance while doing large-scale modifications in your list by waiting with updates until you've completed your work
24
22
* incremental loading: if your source collection supports the feature then AdvancedCollectionView will do as well (it simply forwards the calls)
25
23
* live shaping: when constructing the `AdvancedCollectionView` you may specify that the collection use live shaping. This means that the collection will re-filter or re-sort if there are changes to the sort properties or filter properties that are specified using `ObserveFilterProperty`
26
24
27
-
## Example
28
-
29
-
```csharp
30
-
usingCommunityToolkit.WinUI.Collections;
31
-
32
-
// Grab a sample type
33
-
publicclassPerson
34
-
{
35
-
publicstringName { get; set; }
36
-
}
25
+
The `AdvancedCollectionView` is a good replacement for WPF's `CollectionViewSource`.
37
26
38
-
// Set up the original list with a few sample items
39
-
varoc=newObservableCollection<Person>
40
-
{
41
-
newPerson { Name="Staff" },
42
-
newPerson { Name="42" },
43
-
newPerson { Name="Swan" },
44
-
newPerson { Name="Orchid" },
45
-
newPerson { Name="15" },
46
-
newPerson { Name="Flame" },
47
-
newPerson { Name="16" },
48
-
newPerson { Name="Arrow" },
49
-
newPerson { Name="Tempest" },
50
-
newPerson { Name="23" },
51
-
newPerson { Name="Pearl" },
52
-
newPerson { Name="Hydra" },
53
-
newPerson { Name="Lamp Post" },
54
-
newPerson { Name="4" },
55
-
newPerson { Name="Looking Glass" },
56
-
newPerson { Name="8" },
57
-
};
58
-
59
-
// Set up the AdvancedCollectionView with live shaping enabled to filter and sort the original list
Copy file name to clipboardExpand all lines: components/Collections/samples/AdvancedCollectionViewSample.xaml
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1
+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
Copy file name to clipboardExpand all lines: components/Collections/samples/AdvancedCollectionViewSample.xaml.cs
+11-8Lines changed: 11 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,24 +3,29 @@
3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
usingCommunityToolkit.WinUI.Collections;
6
+
usingSystem.Diagnostics.CodeAnalysis;
6
7
7
8
namespaceCollectionsExperiment.Samples;
8
9
9
-
[ToolkitSample(id:nameof(AdvancedCollectionViewSample),"AdvancedCollectionView",description:$"A sample for showing how to create and use a {nameof(AdvancedCollectionView)}.")]
10
+
[ToolkitSample(id:nameof(AdvancedCollectionViewSample),"AdvancedCollectionView",description:$"A sample for showing how to create and use a {nameof(AdvancedCollectionView)} for sorting and filtering.")]
0 commit comments