diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 3d4c0a45..fb852cfb 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -20,4 +20,4 @@ contact_links: about: "The Windows Community Toolkit uses Uno Platform for cross-platform WinUI. See the Uno Platform repo for issues specific to running on non-Windows platforms:" - name: Discord url: https://aka.ms/wct/discord - about: "Join the UWP Discord Server and talk to us in the #community-toolkit channel." + about: "Join the Windows App Community Discord Server and talk to us in the #community-toolkit channel." diff --git a/components/Behaviors/src/CommunityToolkit.WinUI.Behaviors.csproj b/components/Behaviors/src/CommunityToolkit.WinUI.Behaviors.csproj index 05f3c37b..402d7526 100644 --- a/components/Behaviors/src/CommunityToolkit.WinUI.Behaviors.csproj +++ b/components/Behaviors/src/CommunityToolkit.WinUI.Behaviors.csproj @@ -8,6 +8,7 @@ CommunityToolkit.WinUI.BehaviorsRns ReadMe.md + true diff --git a/components/Collections/samples/AdvancedCollectionView.md b/components/Collections/samples/AdvancedCollectionView.md index c2c37bd1..bab2750e 100644 --- a/components/Collections/samples/AdvancedCollectionView.md +++ b/components/Collections/samples/AdvancedCollectionView.md @@ -1,8 +1,8 @@ --- title: AdvancedCollectionView author: nmetulev -description: The AdvancedCollectionView is a collection view implementation that support filtering, sorting and incremental loading. It's meant to be used in a viewmodel. -keywords: AdvancedCollectionView, data, sorting, filtering, Collections +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. +keywords: AdvancedCollectionView, CollectionViewSource, data, sorting, filtering, Collections dev_langs: - csharp category: Helpers @@ -12,11 +12,9 @@ issue-id: 0 icon: Assets/AdvancedCollectionView.png --- -> [!Sample AdvancedCollectionViewSample] - ## Usage -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: +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: * sorting your list using the `SortDirection` helper: specify any number of property names to sort on with the direction desired * 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 @@ -24,58 +22,13 @@ In your viewmodel instead of having a public [IEnumerable](https://learn.microso * incremental loading: if your source collection supports the feature then AdvancedCollectionView will do as well (it simply forwards the calls) * 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` -## Example - -```csharp -using CommunityToolkit.WinUI.Collections; - -// Grab a sample type -public class Person -{ - public string Name { get; set; } -} +The `AdvancedCollectionView` is a good replacement for WPF's `CollectionViewSource`. -// Set up the original list with a few sample items -var oc = new ObservableCollection -{ - new Person { Name = "Staff" }, - new Person { Name = "42" }, - new Person { Name = "Swan" }, - new Person { Name = "Orchid" }, - new Person { Name = "15" }, - new Person { Name = "Flame" }, - new Person { Name = "16" }, - new Person { Name = "Arrow" }, - new Person { Name = "Tempest" }, - new Person { Name = "23" }, - new Person { Name = "Pearl" }, - new Person { Name = "Hydra" }, - new Person { Name = "Lamp Post" }, - new Person { Name = "4" }, - new Person { Name = "Looking Glass" }, - new Person { Name = "8" }, -}; - -// Set up the AdvancedCollectionView with live shaping enabled to filter and sort the original list -var acv = new AdvancedCollectionView(oc, true); - -// Let's filter out the integers -int nul; -acv.Filter = x => !int.TryParse(((Person)x).Name, out nul); - -// And sort ascending by the property "Name" -acv.SortDescriptions.Add(new SortDescription("Name", SortDirection.Ascending)); - -// Let's add a Person to the observable collection -var person = new Person { Name = "Aardvark" }; -oc.Add(person); +## Example -// Our added person is now at the top of the list, but if we rename this person, we can trigger a re-sort -person.Name = "Zaphod"; // Now a re-sort is triggered and person will be last in the list +The following is a complete example of how to perform ... -// AdvancedCollectionView can be bound to anything that uses collections. -YourListView.ItemsSource = acv; -``` +> [!Sample AdvancedCollectionViewSample] ## Remarks diff --git a/components/Collections/samples/AdvancedCollectionViewSample.xaml b/components/Collections/samples/AdvancedCollectionViewSample.xaml index 80801029..58349990 100644 --- a/components/Collections/samples/AdvancedCollectionViewSample.xaml +++ b/components/Collections/samples/AdvancedCollectionViewSample.xaml @@ -1,9 +1,9 @@ - + @@ -17,8 +17,9 @@ - - + + + ItemTemplate="{StaticResource EmployeeDataTemplate}" + ItemsSource="{x:Bind EmployeeCollection}" /> + ItemTemplate="{StaticResource EmployeeDataTemplate}" + ItemsSource="{x:Bind CollectionView}" /> diff --git a/components/Collections/samples/AdvancedCollectionViewSample.xaml.cs b/components/Collections/samples/AdvancedCollectionViewSample.xaml.cs index a7482a6d..8dfb75e6 100644 --- a/components/Collections/samples/AdvancedCollectionViewSample.xaml.cs +++ b/components/Collections/samples/AdvancedCollectionViewSample.xaml.cs @@ -3,13 +3,16 @@ // See the LICENSE file in the project root for more information. using CommunityToolkit.WinUI.Collections; +using System.Diagnostics.CodeAnalysis; namespace CollectionsExperiment.Samples; -[ToolkitSample(id: nameof(AdvancedCollectionViewSample), "AdvancedCollectionView", description: $"A sample for showing how to create and use a {nameof(AdvancedCollectionView)}.")] +[ToolkitSample(id: nameof(AdvancedCollectionViewSample), "AdvancedCollectionView", description: $"A sample for showing how to create and use a {nameof(AdvancedCollectionView)} for sorting and filtering.")] public sealed partial class AdvancedCollectionViewSample : Page { - public ObservableCollection? oc; + public ObservableCollection EmployeeCollection { get; private set; } + + public AdvancedCollectionView CollectionView { get; private set; } public AdvancedCollectionViewSample() { @@ -17,57 +20,56 @@ public AdvancedCollectionViewSample() Setup(); } + [MemberNotNull(nameof(EmployeeCollection))] + [MemberNotNull(nameof(CollectionView))] private void Setup() { // left list - oc = new ObservableCollection + EmployeeCollection = new() { - new Person { Name = "Staff" }, - new Person { Name = "42" }, - new Person { Name = "Swan" }, - new Person { Name = "Orchid" }, - new Person { Name = "15" }, - new Person { Name = "Flame" }, - new Person { Name = "16" }, - new Person { Name = "Arrow" }, - new Person { Name = "Tempest" }, - new Person { Name = "23" }, - new Person { Name = "Pearl" }, - new Person { Name = "Hydra" }, - new Person { Name = "Lamp Post" }, - new Person { Name = "4" }, - new Person { Name = "Looking Glass" }, - new Person { Name = "8" }, + new() { Name = "Staff" }, + new() { Name = "42" }, + new() { Name = "Swan" }, + new() { Name = "Orchid" }, + new() { Name = "15" }, + new() { Name = "Flame" }, + new() { Name = "16" }, + new() { Name = "Arrow" }, + new() { Name = "Tempest" }, + new() { Name = "23" }, + new() { Name = "Pearl" }, + new() { Name = "Hydra" }, + new() { Name = "Lamp Post" }, + new() { Name = "4" }, + new() { Name = "Looking Glass" }, + new() { Name = "8" }, }; - LeftList.ItemsSource = oc; - // right list - var acv = new AdvancedCollectionView(oc); - int nul; - acv.Filter = x => !int.TryParse(((Person)x).Name, out nul); - acv.SortDescriptions.Add(new SortDescription("Name", SortDirection.Ascending)); + AdvancedCollectionView acv = new(EmployeeCollection); + acv.Filter = x => !int.TryParse(((Employee)x).Name, out _); + acv.SortDescriptions.Add(new(nameof(Employee.Name), SortDirection.Ascending)); - RightList.ItemsSource = acv; + CollectionView = acv; } private void Add_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(NewItemBox.Text)) { - oc!.Insert(0, new Person { Name = NewItemBox.Text }); + EmployeeCollection.Insert(0, new Employee { Name = NewItemBox.Text }); NewItemBox.Text = ""; } } +} +/// +/// A sample class used to show how to use the class. +/// +public partial class Employee +{ /// - /// A sample class used to show how to use the interface. + /// Gets or sets the name of the person. /// - public class Person - { - /// - /// Gets or sets the name of the person. - /// - public string? Name { get; set; } - } + public string? Name { get; set; } } diff --git a/components/Collections/samples/Collections.Samples.csproj b/components/Collections/samples/Collections.Samples.csproj index 1aa967d9..3439c3f9 100644 --- a/components/Collections/samples/Collections.Samples.csproj +++ b/components/Collections/samples/Collections.Samples.csproj @@ -23,4 +23,10 @@ PreserveNewest + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/components/Collections/samples/IncrementalLoadingCollectionSample.xaml b/components/Collections/samples/IncrementalLoadingCollectionSample.xaml index 2557ed51..19ab8f69 100644 --- a/components/Collections/samples/IncrementalLoadingCollectionSample.xaml +++ b/components/Collections/samples/IncrementalLoadingCollectionSample.xaml @@ -1,9 +1,9 @@ - + @@ -19,18 +19,18 @@