CommunityToolkit/WindowsCommunityToolkit

TokenizingTextBox Binding Layout Conflict for ItemsSource

Open

#3.712 aberto em 1 de fev. de 2021

Ver no GitHub
 (4 comments) (0 reactions) (0 assignees)C# (1.403 forks)batch import
bug :bug:help wantedhelpers :raised_hand:unable to reproduce :heavy_multiplication_x:

Métricas do repositório

Stars
 (5.708 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

Describe the bug

Can't set binding to the TokenizingTextBox ItemsSource in XAML directly. This seems to work in the sample app, but it's doing it from code-behind after the control has been loaded.

Steps to Reproduce

Have an ObservableCollection<string> of items in my code. Then trying to bind it directly to the TokenizingTextBox:

<controls:TokenizingTextBox ItemsSource="{x:Bind MyItems, Mode=TwoWay}"/>

(Doesn't matter if OneWay or TwoWay.)

Fails on application launch.

Expected behavior

Able to bind to ItemsSource directly in XAML. It should pre-populate any items from the backing collection, and then any edits from the user should be seen in my backing collection as well.

Environment

NuGet Package(s): build746 (latest main)

Package Version(s): 

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] May 2020 Update (19041)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] May 2020 Update (19041)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [x] 2019 (version: ) 
- [ ] 2019 Preview (version: )

Additional context

Child collection must not be modified during measure or arrange.
   at Windows.UI.Xaml.Controls.ItemsControl.put_ItemsSource(Object value)
   at Project.Views.MainPage.XamlBindingSetters.Set_Windows_UI_Xaml_Controls_ItemsControl_ItemsSource(ItemsControl obj, Object value, String targetNullValue)
   at Project.Views.MainPage.MainPage_obj5_Bindings.Update_MyItems(ObservableCollection`1 obj, Int32 phase)
   at Project.Views.MainPage.MainPage_obj5_Bin

I am swapping out my collection object depending on if I have values, so if I remove all initializations of my backing ObservableCollection then the app loads, but the control is disabled. Though sometimes I get:

System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)

Guia do colaborador