WPF DataGridCheckBoxColumn Checkbox问题

在Datagrid 中使用Checkbox列遇到如下问题:

<DataGridCheckBoxColumn Binding= ”{Binding IsChecked}” Header="表头" CanUserSort=”False”>
</DataGridCheckBoxColumn>

代码如上:问题1:DataGridCheckBoxColumn需要点击两次才可以选中!

解决方案:设置ElementStyle:问题1解决

<DataGridCheckBoxColumn Binding= ”{Binding IsChecked}” Header="表头" CanUserSort=”False”>
CanUserSort=”False”>
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox" >
<Setter Property= ”HorizontalAlignment" Value= "Center" />
</Style>
</DataGridCheckBoxColumn. ElementStyle>
</DataGridCheckBoxColumn>

但是,以上代码又带来问题2:binging失效,结果不会通知到IsChecked属性中去

<DataGridCheckBoxColumn Binding= ”{Binding IsChecked, Mode= TwoWay, UpdateSourceTrigger=PropertyChanged}” Header="表头" CanUserSort=”False”>
CanUserSort=”False”>
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox" >
<Setter Property= ”HorizontalAlignment" Value= "Center" />
</Style>
</DataGridCheckBoxColumn. ElementStyle>
</DataGridCheckBoxColumn>

解决方案:

 修改Binding= ”{Binding IsChecked, Mode= TwoWay, UpdateSourceTrigger=PropertyChanged}”

问题解决。

发布了18 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_28368039/article/details/105113927