如何使用复选框列和绑定从 Xceed\Extended WPF Toolkit 设置数据网格控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20203874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set up the datagrid control from the Xceed\Extended WPF Toolkit with checkbox column and binding
提问by Gern Blanston
I'm trying to swap out a WPF datagrid to a xceed\Extended WPF Toolkit DataGridControl.
我正在尝试将 WPF 数据网格换成 xceed\Extended WPF Toolkit DataGridControl。
I need to react to the click event in a checkbox column ... to summarizing a number of other columns.
我需要对复选框列中的点击事件做出反应......总结其他一些列。
In the existing datagrid I have a checkbox column, that is bound to a Observable Collection and I call a method if any check box is checked\unchecked. The xaml I use for this, which works, is as such:
在现有的数据网格中,我有一个复选框列,它绑定到一个 Observable 集合,如果任何复选框被选中\未选中,我将调用一个方法。我为此使用的 xaml 是这样的:
<DataGridTemplateColumn Width="40" Header="Inc">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox
IsChecked="{Binding Include ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Checked="CheckBoxUpdated" Unchecked="CheckBoxUpdated" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
For the xceed datagridcontrol I started with the simple syntax below, and the the initial binding seemed OK, but I don't have a click event to respond to:
对于 xceed datagridcontrol 我从下面的简单语法开始,初始绑定看起来没问题,但我没有点击事件来响应:
<xcdg:Column FieldName="Include" Title="Inc" />
Now I tried to do something similar to the original code using the xceed datagridcontrol, as such:
现在我尝试使用 xceed datagridcontrol 执行类似于原始代码的操作,如下所示:
<xcdg:Column FieldName="Include" Title="Inc" Width="*" >
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>
But I don't think this is the correct syntax. It seems the binding is not working ... based on the initial values of the collection.
但我认为这不是正确的语法。似乎绑定不起作用......基于集合的初始值。
(note code behind sets this items source as such dg.ItemsSource = collectionView;)
(注意后面的代码将此项目源设置为 dg.ItemsSource = collectionView;)
Any ideas on how to setup a checkbox DataTemplate and the binding correctly?
关于如何正确设置复选框 DataTemplate 和绑定的任何想法?
Thanks
谢谢
回答by Gern Blanston
I just found a post at xceed forumsthat gave me the syntax I needed, that to set the FieldName=".", not FieldName="Include" . My guess is that having FieldName="Include" and the "{Binding Include ..." was confusing the binding.
我刚刚在xceed 论坛上找到了一个帖子,它为我提供了所需的语法,即设置 FieldName="." 而不是 FieldName="Include" 。我的猜测是 FieldName="Include" 和 "{Binding Include ..." 混淆了绑定。
<xcdg:Column FieldName="." Title="Inc" Width="*" >
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>
回答by xtds
Your solution to your question wasn't working for me, what did work however:
您对问题的解决方案对我不起作用,但是什么有效:
Either
任何一个
<xcdg:Column ...
if the type is boolean it will automaticly create a checkbox for it, you'll have to click 3 times though (column edit -> (un)check -> column out) which can be annoying.
如果类型是布尔值,它将自动为其创建一个复选框,但您必须单击 3 次(列编辑 -> (un)check -> 列出),这可能很烦人。
OR
或者
<xcdg:Column FieldName="ckb1" DisplayMemberBinding="{Binding Path=IsThisChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<CheckBox IsChecked="{xcdg:CellEditorBinding NotifyOnSourceUpdated=True}" HorizontalAlignment="Center" />
</DataTemplate>
</xcdg:Column.CellContentTemplate>
</xcdg:Column>
Which doesn't need all the clicking
哪个不需要所有的点击

