I am using the DataGrid from the WPF toolkit in .NET 3.5.
I have a datagrid column bound to a boolean property from my source object.
The checkbox is calling the boolean's properties get accessor correctly.
However when checking or unchecking the box the get instead of the set is being called.
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Object, Source={StaticResource model}, Mode=TwoWay}">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{Binding BoolProperty, mode=TwoWay}"/>
</DataGrid.Columns>
</DataGrid>
When I instead use a DataGridTemplateColumn with a Checkbox in it the property is set correctly however then it is more complicated to create a nice layout.
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding BoolProperty, Mode=TwoWay}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
What am I doing wrong using the DataGridCheckBoxColumn?
I got same problem with you ,here is my solution
<CheckBox HorizontalAlignment="Center" IsChecked="{Binding BoolProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
My solution was to set UpdateSourceTrigger to PropertyChanged.
<DataGridCheckBoxColumn Header="Bool property" Binding="{Binding BoolProperty, UpdateSourceTrigger=PropertyChanged}"></DataGridCheckBoxColumn>
In a DataGrid
the bindings do not get committed until you end editing of the row/cell. If you press enter the binding will apply back to the source.
Using a template like this overrides that behaviour, i wouldn't recommend that though. Also setting TwoWay
explicitly should not be necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With