KaJo
KaJo

Reputation: 199

WPF: Problem with Checkbox when binding datatrigger to property "Ischecked"

I have a checkbox in GridViewColumn which i use for show/change database value. The click event for the checkbox is used for change value in the database. For handling the state of property "IsChecked" I'm using datatrigger and a setter, se xaml code below:

<Style TargetType="CheckBox">
    <Setter Property="IsEnabled" Value="True" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=ID, Converter={StaticResource Converter}}"   Value="true">
            <Setter Property="IsChecked" Value="True"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

The binding works great until I click the checkbox. After I clicked the checkbox for the first time the state of the property "IsChecked" don't updates if a manually in the Database change the value which i mapped to the property "IsChecked". If I map for example the same value to the property "Content" of the checkbox the trigger works fine even after I've clicked the checkbox.

Does anyone no whats the problem is?

Upvotes: 4

Views: 9589

Answers (3)

Pop Catalin
Pop Catalin

Reputation: 62960

Shouldn't

<Style TargetType="CheckBox">

instead be:

 <Style TargetType="{x:Type CheckBox}">

Edit:

you could try this:

    <Style TargetType="{x:Type CheckBox}" >
        <Setter Property="IsChecked" Value="{Binding Path=ID, Converter={StaticResource Converter}}" />
    </Style>

Upvotes: 4

Arcturus
Arcturus

Reputation: 27055

In stead of using Click to determine the changes, perhaps you can use the Checked and Unchecked events ?

Upvotes: 0

OliK
OliK

Reputation: 265

You can try to add a second data trigger to set the checkbox to false. As I can see from your code you set the IsChecked only to true, but never to false.

Upvotes: 1

Related Questions