I have the following code inside a XamDataGrid:
<igDp:Field Name="IsBlackChecked" Label="Black Image" />
The problem is that its not two way binding. When I click the Checkbox in the UI the value is not being set.
I have tried the following solution:
<igWPF:Field Name="IsBlackChecked" Label="Black Image" Width="Auto" >
<igWPF:Field.Settings>
<igWPF:FieldSettings AllowEdit="True">
<igWPF:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igWPF:XamCheckEditor}"
BasedOn="{StaticResource {x:Type igWPF:XamCheckEditor}}" > <Setter Property="IsChecked" Value="{Binding DataItem.IsBlackChecked, Mode=TwoWay}"/>
</Style>
</igWPF:FieldSettings.EditorStyle>
<igWPF:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igWPF:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}">
<CheckBox IsChecked="{Binding DataItem.IsBlackChecked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igWPF:FieldSettings.CellValuePresenterStyle>
</igWPF:FieldSettings>
</igWPF:Field.Settings>
</igWPF:Field>
This does provides me with two way binding but it changes the style of the cell and the border lines are gone,
How can I specify two way binding in this field in the first options / restore the borderlines in the second?
Above is two way
bindingby default(you can check for any datatype). The real problems in your scenario could becheckboxtheCellvaluePresenterwill consumemoues click event. so first you have to select a cell then if then you'll click oncheckboxthecheckboxwill get checked. (this was happening in my case.)INotifyProertyChangedin youmodel class. so may be when you'll tab away(collection notification happens) fromrecordthe change will get reflected in theproperty(hopefully).One Big Flaw:
you have created both
editorstyleandcellvaluepresenterstyle. Onlyeditorstyleis enough.(changing thecellvaluepresentrerstyle will change the look and feel & interaction behave of a cell. Thats why there is noborderon yourcelland probably selection indication would have gone wrong too.)In
editorstyledefine thetemplate/bindingsas you need for checkbox. Then both functionally and aesthetically the solution will be complete.Above is a complex
controltemplateforXamTextEditor. and use this style in yourfieldsettingeditorstyleproperty.Note: Don't recreate
CellValuePresenterTemplate unless there is an absolute necessity. Your case only requires to create anEditorStyleof a cell to bind a bool property tocheckbox. In short you can move yourCellValuePresenterTemplate code inEditorStylewith some adjustments to binding.