Custom CheckBox in WPF DataGrid does not update binding

Posted by Pakman on Stack Overflow See other posts from Stack Overflow or by Pakman
Published on 2010-05-28T03:45:52Z Indexed on 2010/05/28 20:31 UTC
Read the original article Hit count: 1231

Filed under:
|
|
|

In my Visual Studio 2010 WPF application, I have the following (simplified) style:

<Style x:Key="MyStyle" TargetType="{x:Type CheckBox}">  
    <Setter Property="Background" Value="Blue" />  
</Style>

If I use it as the ElementStyle AND EditingElementStyle in my DataGridCheckBoxColumn:

<DataGridCheckBoxColumn Binding="{Binding IsEnabled}"  
    ElementStyle="{StaticResource MyStyle}"  
    EditingElementStyle="{StaticResource MyStyle}" />

Then my binding, IsEnabled, does not toggle when I check/uncheck a row's checkbox. If I remove either ElementStyle, EditingElementStyle, or both, then the binding updates no problem. Why is this?!

Also, I tried to work around the problem using the following code:

<DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsEnabled}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

However, the problem remains.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf