-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] how to show added children in grouped collection // workaround for ObservableGroup immutable key restriction? #3519
Comments
Hello hansmbakker, thank you for your interest in Windows Community Toolkit! I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible.. Other community members may also answer the question and provide feedback 🙌 |
@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! |
Also, maybe good to mention @vgromfeld who created these types originally :) |
@hansmbakker |
@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? |
@hansmbakker Yes, you can modify the toolkit classes. The |
@hansmbakker thanks for raising the issue, did you also want to submit a PR for this change? |
Looking at it in more detail now, I see that the I want to base two viewmodel types on them, but because of them being Were there any design considerations to add this restriction? |
@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 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. |
## Fixes #3519 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> Removes two restrictions from `ObservableGroup` to make it usable in more situations. In my case, I wanted to be able to rename the groups (for this I needed a mutable key), and I wanted to add properties on the group level (I needed to unseal it) - Removes the immutable restriction on the `Key` property and makes the `Key` property observable. - Removes the `sealed` keyword from `ObservableGroup` ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <!-- - Bugfix --> - Feature <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> `ObservableGroup` has an immutable `Key` property `ObservableGroup` is not inheritable ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> `ObservableGroup` has a mutable `Key` property `ObservableGroup` is inheritable ## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../readme.md#supported) - [x] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: MicrosoftDocs/WindowsCommunityToolkitDocs#394 - [x] Sample in sample app has been added / updated (for bug fixes / features) --> _no update needed_ - [x] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) --> _not applicable_ - [x] Tests for the changes have been added (for bug fixes / features) (if applicable) --> _not applicable_ - [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*) --> _not applicable_ - [ ] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected. --> ## Other information
I'm trying to build an app that allows modifying a grouped collection (nested
ObservableCollection
) in aListView
. I am showing the grouped collection in theListView
using aCollectionViewSource
.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:
Imagine this (simplified example): having an
ObservableCollection<Book>
, and everyBook
has aTitle
(string
) and anObservableCollection<Uri>
for some images.I want to add books, edit their title, and also add
Uri
s of images and edit them.ListView
, I haveGroupStyle
with aHeaderTemplate
containingTextBox
to edit theTitle
sButton
to insert new Uri items --> here is my issueItemTemplate
containing aTextBox
for the imageUri
sListView
I have aButton
to add newBook
items to theObservableCollection<Book>
With my current solution (
ObservableCollection<Book>
withTitle
andObservableCollection<Uri>
insideBook
), I can editBook
Titles andUri
s, but when I add a newUri
, theListView does
not show it because theCollectionViewSource
does not notice it, because theObservableCollection<Book>
does not emit aCollectionChanged
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?The text was updated successfully, but these errors were encountered: