I’m writing a tag control, based on the listbox.
It is displaying the ListBox items using following template:
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<local:TagControl Text="{Binding Path=., Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Remove="RemoveItem" />
</DataTemplate>
</Setter.Value>
</Setter>
I’ve noticed that when I update TagControl’s text, the original item in the ListBox does not get updated. I’m using ObservableCollection<string> as items source.
TagControl implements INotifyPropertyChanged and calls the event.
What am I doing wrong?
I’ve reproduced your problem and can offer a solution. The
ObservableCollection<string>is enumerated using IEnumerable which is read-only.If you replace the
ObservableCollection<string>withObservableCollection<DataItem>whereand then bind to Name in your DataTemplate, the enumerated DataItem is read-only, but the Name property is read-write and will be updated when you edit the text in the list item.