WPF: checkbox issue when binding datatrigger to "Ischecked" property

I have a checkbox in the GridViewColumn that I use to display / modify the database. The click event for this flag is used to indicate the change in the database. To process the "IsChecked" property state, I use datatrigger and 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>

Binding works fine until I check the box. After I first checked the box, the state of the IsChecked property is not updated if I manually change the value in the database that I matched with the IsChecked property. If I match, for example, the same value with the "Content" property of a flag, the trigger works fine even after I clicked on this flag.

Does anyone not know what the problem is?

+3
source share
3 answers

Not worth it

<Style TargetType="CheckBox">

instead of this:

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

Edit:

you can try the following:

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

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

0
source

Instead of using Click to identify changes, maybe you can use the Checked and Unchecked events?

0
source

Source: https://habr.com/ru/post/1699500/


All Articles