I have a column class which uses view model base to implement INotifyPropertyChanged (lazy I know):
public class Column : ViewModelBase
{
public string ColumnName { get; set; }
public bool Anonymize { get; set; }
}
And then a list of columns:
public class Columns : ObservableCollection<Column>
{
}
In my view model I have a property columns and I am binding that to a combo box with a checkbox and textblock:
private Columns _tableColumns;
public Columns TableColumns
{
get
{
return _tableColumns;
}
set
{
_tableColumns = value;
OnPropertyChanged("TableColumns");
}
}
<ComboBox Name="cbColumns" ItemsSource="{Binding TableColumns}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Anonymize, Mode=TwoWay}" />
<TextBlock Text="{Binding ColumnName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
When I change the Anonymize property through the checkbox on an item, how do make the Columns property change in the view model to reflect this?
Your
Columnclass needs to implementINotifyPropertyChanged(which you say it does). You also need to raise that event it when the value ofAnonymizechanges (which you don’t).