Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Microsoft.Toolkit/Collections/ObservableGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;

Expand All @@ -16,8 +17,10 @@ namespace Microsoft.Toolkit.Collections
/// <typeparam name="TKey">The type of the group key.</typeparam>
/// <typeparam name="TValue">The type of the items in the collection.</typeparam>
[DebuggerDisplay("Key = {Key}, Count = {Count}")]
public sealed class ObservableGroup<TKey, TValue> : ObservableCollection<TValue>, IGrouping<TKey, TValue>, IReadOnlyObservableGroup
public class ObservableGroup<TKey, TValue> : ObservableCollection<TValue>, IGrouping<TKey, TValue>, IReadOnlyObservableGroup
{
private TKey key;

/// <summary>
/// Initializes a new instance of the <see cref="ObservableGroup{TKey, TValue}"/> class.
/// </summary>
Expand Down Expand Up @@ -49,9 +52,21 @@ public ObservableGroup(TKey key, IEnumerable<TValue> collection)
}

/// <summary>
/// Gets the key of the group.
/// Gets or sets the key of the group.
/// </summary>
public TKey Key { get; }
public TKey Key
{
get => this.key;
set
{
if (!EqualityComparer<TKey>.Default.Equals(this.key, value))
{
this.key = value;

OnPropertyChanged(new PropertyChangedEventArgs(nameof(Key)));
}
}
}

/// <inheritdoc/>
object IReadOnlyObservableGroup.Key => Key;
Expand Down