Skip to content

[Question] how to show added children in grouped collection // workaround for ObservableGroup immutable key restriction? #3519

@hansmbakker

Description

@hansmbakker

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.

This is being discussed in in this StackOverflow item as well.

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions