diff --git a/Microsoft.Toolkit/Collections/ObservableGroup.cs b/Microsoft.Toolkit/Collections/ObservableGroup.cs index 304be89e496..ce828934917 100644 --- a/Microsoft.Toolkit/Collections/ObservableGroup.cs +++ b/Microsoft.Toolkit/Collections/ObservableGroup.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Diagnostics; using System.Linq; @@ -16,8 +17,13 @@ namespace Microsoft.Toolkit.Collections /// The type of the group key. /// The type of the items in the collection. [DebuggerDisplay("Key = {Key}, Count = {Count}")] - public sealed class ObservableGroup : ObservableCollection, IGrouping, IReadOnlyObservableGroup + public class ObservableGroup : ObservableCollection, IGrouping, IReadOnlyObservableGroup { + /// + /// The cached for + /// + private static readonly PropertyChangedEventArgs KeyChangedEventArgs = new PropertyChangedEventArgs(nameof(Key)); + /// /// Initializes a new instance of the class. /// @@ -48,10 +54,24 @@ public ObservableGroup(TKey key, IEnumerable collection) Key = key; } + private TKey key; + /// - /// Gets the key of the group. + /// Gets or sets the key of the group. /// - public TKey Key { get; } + public TKey Key + { + get => this.key; + set + { + if (!EqualityComparer.Default.Equals(this.key, value)) + { + this.key = value; + + OnPropertyChanged(KeyChangedEventArgs); + } + } + } /// object IReadOnlyObservableGroup.Key => Key;