diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj index 77be6020d17..7212c223cc6 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj +++ b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj @@ -518,6 +518,9 @@ ImageExLazyLoadingControl.xaml + + ObservableGroupPage.xaml + OnDevicePage.xaml @@ -542,6 +545,7 @@ + @@ -939,6 +943,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ObservableGroup/ObservableGroup.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ObservableGroup/ObservableGroup.bind new file mode 100644 index 00000000000..d4344fd4d6d --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ObservableGroup/ObservableGroup.bind @@ -0,0 +1,40 @@ +// Grab a sample type +public class Person +{ + public string Name { get; set; } +} + +// Set up the original list with a few sample items +var contacts = new[] +{ + new Person { Name = "Staff" }, + new Person { Name = "Swan" }, + new Person { Name = "Orchid" }, + new Person { Name = "Flame" }, + new Person { Name = "Arrow" }, + new Person { Name = "Tempest" }, + new Person { Name = "Pearl" }, + new Person { Name = "Hydra" }, + new Person { Name = "Lamp Post" }, + new Person { Name = "Looking Glass" }, +}; + +// Group the contacts by first letter +var grouped = contacts.GroupBy(GetGroupName).OrderBy(g => g.Key); + +// Create an observable grouped collection +var contactsSource = new ObservableGroupedCollection(grouped); + +// Create a read-only observable grouped collection +// Note: This step is optional. It is usually used in view models to expose the collection as read-only and prevent the view from altering it. +var readonlyContacts = new ReadOnlyObservableGroupedCollection(contactsSource); + +// Set up the CollectionViewSource +var cvs = new CollectionViewSource +{ + IsSourceGrouped = True, + Source = readonlyContacts, +}; + +// Bind the CollectionViewSource to anything that supports grouped collections. +ContactsList.ItemsSource = cvs.View; \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ObservableGroup/ObservableGroupPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ObservableGroup/ObservableGroupPage.xaml new file mode 100644 index 00000000000..d57785e8ac1 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ObservableGroup/ObservableGroupPage.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +