I have a combobox and its datacontext property is assigned to ObservableCollection.
<ComboBox
Name="CB"
ItemsSource="{Binding}"
DisplayMemberPath="Name"
IsSynchronizedWithCurrentItem="True">
</ComboBox>
<TextBlock
Name="TB"
Text="{Binding ElementName=CB,Path=SelectedItem.Name,UpdateSourceTrigger=PropertyChanged}"
></TextBlock>
C#
class Person
{
public string Name { get; set; }
}
ObservableCollection<Person> people = new ObservableCollection<Person>( new List<Person>()
{
new Person(){Name="A"},
new Person(){Name="B"},
new Person(){Name="C"},
new Person(){Name="D"},
});
people[0].Name = "Z"; // When button clicked, i execute this
I also have a button when clicked updates the first employee's Name to something else.
When the first employee is the selected one, and I clicked the button even though underlying name changes, it's not reflected in the UI until I change the selected item and re-select the first one.
What should I do to achieve what I want? I thought when ObservableCollection that combobox is bound to changes, it would have been reflected in the ui.