I have a WPF application containing several ComboBoxes. The ItemsSource of some of the comboboxes is bound to a list of objects. I want to bind a text property of each combobox to some property of MyObject. Each time a user selects some row in MyListView, I update the properties of MyObject, and I want the text properties of the comboboxes to update as well.
This is the XAML for one of the comboboxes:
<StackPanel Orientation="Vertical" x:Name="StackPanel_MyStackPanel">
<ComboBox x:Name="comboBox_MyComboBox"
IsEditable="True"
ItemsSource="{Binding}"
Text="{Binding Path=MyProperty}" />
</StackPanel>
In the code behind:
MyObject myObject = new MyObject();
// On the selection changed event handler of the MyListView,
// I update the MyProperty of the myObject.
this.StackPanel_MyStackPanel.DataContext = myObject;
the definition of MyObject:
public class MyObject
{
private string _MyProperty;
public string MyProperty
{
get { return _MyProperty; }
set { _MyProperty = value; }
}
}
This is not working…. and I don’t know why.
Your data class needs to implement INotifyPropertyChanged: