You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
[Question] how to show added children in grouped collection // workaround for ObservableGroup immutable key restriction? #3519
I'm trying to build an app that allows modifying a grouped collection (nested ObservableCollection) in a ListView. I am showing the grouped collection in the ListView using a CollectionViewSource.
I am not yet using the ObservableGroup / ObservableGroupedCollection yet, my question is whether they are a viable option.
I would like to achieve the following:
edit the group names
edit the individual items
add / remove new groups
add / remove individual items
Imagine this (simplified example): having an ObservableCollection<Book>, and every Book has a Title (string) and an ObservableCollection<Uri> for some images.
I want to add books, edit their title, and also add Uris of images and edit them.
Inside my ListView, I have
a GroupStyle with a HeaderTemplate containing
TextBox to edit the Titles
a Button to insert new Uri items --> here is my issue
an ItemTemplate containing a TextBox for the image Uris
outside my ListView I have a Button to add new Book items to the ObservableCollection<Book>
With my current solution (ObservableCollection<Book> with Title and ObservableCollection<Uri> inside Book), I can edit Book Titles and Uris, but when I add a new Uri, the ListView does not show it because the CollectionViewSource does not notice it, because the ObservableCollection<Book> does not emit a CollectionChanged event.
Then I found ObservableGroup / ObservableGroupedCollection from Windows Community Toolkit, but I'm unsure whether that will solve my issue? Since the Key is immutable I assume they won't let me edit the Book Titles?
changed the title [-][Question] how to add children to grouped collection // workaround for ObservableGroup immutable key restriction?[/-][+][Question] how to show added children in grouped collection // workaround for ObservableGroup immutable key restriction?[/+]on Oct 4, 2020
@hansmbakker that's a good question. Let me loop in the team and see if anyone will be to assist you with this or tell you if it's feasible with ObservableGroup or ObservableGroupCollection.
Thank you!
As a workaround, I see this probably can be built with nested ListViews, or with a custom ItemsRepeater, but I was wondering what the "proper" way of doing this is.
So I'm curious to hear what they will say.
@hansmbakkerObservableGroup<TKey, TValue> seems to be a good choice since it provides almost all you need.
The only missing part is to make the ObservableGroup<TKey, TValue>.Key property mutable.
This should be easy to change. ObservableGroup<TKey, TValue> is already inheriting from INotifyPropertyChanged so if you change the Key property to read/write, you can directly raise the property changed event and have the behavior you want.
@michael-hawker I'm providing #3526 as-is: I'm willing to contribute the changes that unblocked me, and I updated the documentation for it, but I feel not confident in changing the larger picture of this as I am not aware of design considerations that were there when these classes were added.
For example I left ObservableGroupedCollectionsealed. Also, I did not update the IReadOnlyObservableGroup because the name suggests it should be immutable.
I want to avoid getting involved in a long-running PR process / ping-ponging this back and forth between me and others; however maintainers have access to the branch in case they want to make modifications to it.
Activity
[-][Question] how to add children to grouped collection // workaround for ObservableGroup immutable key restriction?[/-][+][Question] how to show added children in grouped collection // workaround for ObservableGroup immutable key restriction?[/+]Kyaa-dost commentedon Oct 5, 2020
@hansmbakker that's a good question. Let me loop in the team and see if anyone will be to assist you with this or tell you if it's feasible with ObservableGroup or ObservableGroupCollection.
hansmbakker commentedon Oct 5, 2020
Thank you!
As a workaround, I see this probably can be built with nested
ListViews, or with a customItemsRepeater, but I was wondering what the "proper" way of doing this is.So I'm curious to hear what they will say.
hansmbakker commentedon Oct 5, 2020
Also, maybe good to mention @vgromfeld who created these types originally :)
(#3201)
vgromfeld commentedon Oct 6, 2020
@hansmbakker
ObservableGroup<TKey, TValue>seems to be a good choice since it provides almost all you need.The only missing part is to make the
ObservableGroup<TKey, TValue>.Keyproperty mutable.This should be easy to change.
ObservableGroup<TKey, TValue>is already inheriting fromINotifyPropertyChangedso if you change theKeyproperty to read/write, you can directly raise the property changed event and have the behavior you want.hansmbakker commentedon Oct 6, 2020
@vgromfeld thank you for your response!
Are you suggesting to modify the classes in the WCT?
If so, I was wondering whether the read-only setting was meant for a particular requirement or behaviour?
vgromfeld commentedon Oct 6, 2020
@hansmbakker Yes, you can modify the toolkit classes.
The
Keyproperty is read-only because I didn't need it to be writable when I implemented it 😁.michael-hawker commentedon Oct 6, 2020
@hansmbakker thanks for raising the issue, did you also want to submit a PR for this change?
hansmbakker commentedon Oct 6, 2020
Looking at it in more detail now, I see that the
ObservableGroupandObservableGroupedCollectiontypes aresealed.I want to base two viewmodel types on them, but because of them being
sealedI cannot extend them.Were there any design considerations to add this restriction?
hansmbakker commentedon Oct 6, 2020
@michael-hawker I'm providing #3526 as-is: I'm willing to contribute the changes that unblocked me, and I updated the documentation for it, but I feel not confident in changing the larger picture of this as I am not aware of design considerations that were there when these classes were added.
For example I left
ObservableGroupedCollectionsealed. Also, I did not update theIReadOnlyObservableGroupbecause the name suggests it should be immutable.I want to avoid getting involved in a long-running PR process / ping-ponging this back and forth between me and others; however maintainers have access to the branch in case they want to make modifications to it.
Mutable and subclassable version of ObservableGroup (#3526)