-
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
TokenizingTextBox exposes InterspersedObservableCollection instead of ObservableCollection #4248
Comments
…ng to ItemsSource Avoids bug CommunityToolkit#4248
I've at least started on a fix for the sample itself to work-around the issue here: d528479 I think it's going to be tricky to resolve out-right though as I'm not sure what alternatives we may have here to work around this. I did just try to swap to an ❓ Thinking due to the complexity here (and that it took us a year+ to hit ourselves) that we should move out of 7.1. |
…ng to ItemsSource Avoids bug CommunityToolkit#4248
## Fixes #4210 and Fixes #4158 Cleans up sample for #4248 (though underlying issue remains to be figured out later). Fixes a sample and cleans-up a few items we missed in our nuget packages. Just need to validate output from CI, but should be fairly straight-forward. ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more options below 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? TTB Sample was binding to the internal collection instead of showing binding to a developer provided collection. Some new features were missing from the NuGet package info. ## What is the new behavior? Fixed! 🎉 ## PR Checklist Please check if your PR fulfills the following requirements: <!-- and remove the ones that are not applicable to the current PR --> - [ ] Tested code with current [supported SDKs](../#supported) - [ ] New component - [ ] Pull Request has been submitted to the documentation repository [instructions](../blob/main/Contributing.md#docs). Link: <!-- docs PR link --> - [ ] Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that) - [ ] If control, added to Visual Studio Design project - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/CommunityToolkit/WindowsCommunityToolkit-design-assets) - [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/CommunityToolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [ ] Tests for the changes have been added (for bug fixes / features) (if applicable) - [ ] Header has been added to all new source files (run _build/UpdateHeaders.bat_) - [ ] 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 within minor release cycles or held until major versions. --> ## Other information <!-- Please add any other information that might be helpful to reviewers. -->
Describe the bug
The original intent of the TokenizingTextBox was to not expose the internal collection type of
InterspersedObservableCollection
, and by providing anObservableCollection
to theItemsSource
property, a developer could retrieve only the tokenized elements from the control for their datamodel (or provide them as a pre-population/rehydration on a form).A developer could then access the
Text
or rawItems
properties to enumerate all partial strings with the Tokens if needed.However, in the current implementation, we overwrite the
ItemsSource
value with our InterspersedObservableCollection reference here:WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.cs
Line 62 in 03c3f3c
And more importantly here:
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.cs
Line 94 in 03c3f3c
This means if you try to setup the scenario as we were in the current Sample app or Graph Sample App (see CommunityToolkit/Graph-Controls#149) binding to the ItemsSource property of the TTB directly, you'd get the internal copy of the InterspersedObservableCollection instead of the inner ObservableCollection of only tokened items.
Steps to Reproduce
We can actually observe this in our own sample app (but it was invisible) so we missed it during initial development.
Steps to reproduce the behavior:
PretokenStingContainer
element which shouldn't be part of our collection (only ever exposed on Items and forToString
to get value).We should expect the ItemsControl to be empty at this time.
We can also further show this corruption by performing a few steps.
This should not be the case!
Expected behavior
Binding to the ItemsSource even if we don't provide an external collection should only provide the tokenized items. We should only be able to observe the PretokenStringContainer within the
Items
collection which a developer would check for their own type or callToString
to get the raw values of typed text.Screenshots
Environment
NuGet Package(s): Input
Package Version(s): 7.1.0-rc1
Windows 10 Build Number:
App min and target version:
Device form factor:
Visual Studio version:
Additional context
Updated the Graph Sample for now to avoid this issue and show the more practical pattern here: CommunityToolkit/Graph-Controls#160
Should still resolve this issue here.
I believe we did this the way we did initially as since we're inheriting from
ListViewBase
, we useItemsPresenter
to present the items here:WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.xaml
Lines 111 to 112 in 03c3f3c
ItemsPresenter grabs the
ItemsSource
automatically... it's not something we can set. I'm not sure how we override it either, so this is going to need some thought... 🤔The text was updated successfully, but these errors were encountered: