在我的 WPF 项目中,我datagrid
使用复选框列构建了以下内容:
XAML
<DataGrid AutoGenerateColumns="False"
TargetUpdated="IsIntermediatePointFixedByBracketDataGrid_TargetUpdated">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding=
"{Binding isFixedByBracket, NotifyOnTargetUpdated=True }" />
</DataGrid.Columns>
</DataGrid>
C#
private void IsIntermediatePointFixedByBracketDataGrid_TargetUpdated(object sender,
DataTransferEventArgs e)
{
DataGrid dg = (DataGrid)sender;
if (dg.SelectedIndex != -1
&& ((IsFixedByBracketElement)dg.SelectedItem).isFixedByBracket
!= this.currentIntermediatePosition.isFixedByBracket[dg.SelectedIndex])
{
this.currentIntermediatePosition.isFixedByBracket[dg.SelectedIndex] =
((IsFixedByBracketElement)dg.SelectedItem).isFixedByBracket;
}
}
当我选中/取消选中一个复选框时,TargetUpdated
会引发该事件,但只有当我选择并取消选择包含该复选框的单元格时,该值才会更改。为什么会这样?我怎样才能改变这种行为?