Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Mutable and subclassable version of ObservableGroup
  • Loading branch information
hansmbakker committed Oct 6, 2020
commit 23deea8230908e63519948a169ecb8120784f7bc
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
{
return _key;
}

set
{
_key = value;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Key)));
}
}

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