Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 780
Gern Blanston Avatar asked Feb 15 '23 13:02

Gern Blanston


1 Answers

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>

like image 163
Gern Blanston Avatar answered Feb 19 '23 20:02

Gern Blanston