How to set up the datagrid control from the Xceed\Extended WPF Toolkit with checkbox column and binding

流过昼夜 提交于 2019-11-30 18:29:03

问题


I'm trying to swap out a WPF datagrid to a 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:

<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:

<xcdg:Column   FieldName="Include" Title="Inc" />

Now I tried to do something similar to the original code using the xceed datagridcontrol, as such:

<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;)

Any ideas on how to setup a checkbox DataTemplate and the binding correctly?

Thanks


回答1:


I just found a post at xceed forums that 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.

<xcdg:Column   FieldName="." Title="Inc" Width="*" >
 <xcdg:Column.CellContentTemplate>
  <DataTemplate>
    <CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>

|improve this answer

来源:https://stackoverflow.com/questions/20203874/how-to-set-up-the-datagrid-control-from-the-xceed-extended-wpf-toolkit-with-chec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!