I have a DataGrid that displays a list of items
there is a check box in each row that should change a Boolean field from the corresponding data class
-
I expect the field value to change and the OnPropertyChanged to trigger
-
as the app initializes, the setter is triggered upon list initialization
-
when I click on any checkbox, the setter is never triggered
here is the Control xaml:
<DataGrid x:Name="ModificationsGrid" AutoGenerateColumns="False" ItemsSource="{Binding Value}" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Action">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Enabled, Mode=TwoWay}" VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
The corresponding Data class
using System.ComponentModel;
namespace MyNameSpace.refactor
{
// Refactor operation data
public class RefactorOperation : INotifyPropertyChanged
{
public RefactorOperation(int startLine, int startChar, int endLine, int endChar, string[] content, bool enabled)
{
StartLine = startLine;
StartCharacter = startChar;
EndLine = endLine;
EndCharacter = endChar;
Content = content;
Enabled = enabled;
}
public int StartLine { get; set; }
public int StartCharacter { get; set; }
public int EndLine { get; set; }
public int EndCharacter { get; set; }
public string[] Content { get; set; }
private bool _enabled; // field related to below property
public bool Enabled
{
get { return _enabled; }
set
{
// should trigger on chekcbox interactions
_enabled = value;
OnPropertyChanged(nameof(Enabled));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Am I missing something ?
thanks for your help