我有以下的(简化)风格:自定义复选框在WPF DataGrid不更新绑定
<Style x:Key="MyStyle" TargetType="{x:Type CheckBox}">
<Setter Property="Background" Value="Blue" />
</Style>
如果我把它作为ElementStyle和EditingElementStyle在我DataGridCheckBoxColumn:
<DataGridCheckBoxColumn Binding="{Binding IsEnabled}"
ElementStyle="{StaticResource MyStyle}"
EditingElementStyle="{StaticResource MyStyle}" />
然后我绑定,IsEnabled
,当我检查/取消选中一行的复选框时,不会切换。如果我删除ElementStyle,EditingElementStyle或两者,那么绑定更新没有问题。为什么是这样?!
而且,我尝试使用下面的代码来解决此问题:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsEnabled}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
然而,问题依然存在。
同意 - 这是非常简单的。 – ifinlay 2016-01-21 22:42:04