views:

4127

answers:

5

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?

A: 

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.

A: 

Tanks for the answer, but ive tried that as well. The trigger on property IsSelected works fine with both checking and unchecking depending on incoming value of the ID. But when checkbox is clicked the property IsSelected dont updates anymore when the value of Id is changed. I also tried to bind the property "Content" to same trigger and works fine even afterI clicked the checkbox. So it seems to be a problem only with poperty "IsSelected".

KaJo
A: 

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

Arcturus
A: 

thanks! But in this case these events are not possible to use. The value from database can be changed from other applications as well. I wont my checkbox to show the current value from databes and also give me the possibility to change this value by checking and unchecking the checkbox.

KaJo
+2  A: 

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>
Pop Catalin
Yes thats right. Thanks. But that does'nt help me with my propertytrigger :(
KaJo
Thanks! Your last edit together with some modifications in the converter class (convert back function) solved my problem.
KaJo