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
binding
by default(you can check for any datatype). The real problems in your scenario could becheckbox
theCellvaluePresenter
will consumemoues click event
. so first you have to select a cell then if then you'll click oncheckbox
thecheckbox
will get checked. (this was happening in my case.)INotifyProertyChanged
in youmodel class
. so may be when you'll tab away(collection notification happens) fromrecord
the change will get reflected in theproperty
(hopefully).One Big Flaw:
you have created both
editorstyle
andcellvaluepresenterstyle
. Onlyeditorstyle
is enough.(changing thecellvaluepresentrer
style will change the look and feel & interaction behave of a cell. Thats why there is noborder
on yourcell
and probably selection indication would have gone wrong too.)In
editorstyle
define thetemplate/bindings
as you need for checkbox. Then both functionally and aesthetically the solution will be complete.Above is a complex
controltemplate
forXamTextEditor
. and use this style in yourfieldsetting
editorstyle
property.Note: Don't recreate
CellValuePresenter
Template unless there is an absolute necessity. Your case only requires to create anEditorStyle
of a cell to bind a bool property tocheckbox
. In short you can move yourCellValuePresenter
Template code inEditorStyle
with some adjustments to binding.