I bind the IsEnabled property of a Button to the property of my class of Boolean type IsChecked . But I want the button to be clickable when the IsChecked = false property IsChecked = false . To do this, I add a negative sign in front of the IsChecked property. The button becomes available, since the initial value IsChecked = false , when pressed, this value changes to true , but the button still remains available for pressing. What is the problem? Why is the IsEnabled property unchanged when the IsChecked property changes?

  <Button Command="{Binding Activate}" Width="25" Height="25" IsEnabled="{Binding !IsChecked }"/> 
  • one
    and who said that the sign of negation works? - Monk
  • Your "... property of its class is a Boolean type ..." gives a PropertyChanged event? If not, then the UI and the button in particular do not know anything about the change in the property. Yes, I'm not sure what ! will work as it should, for such a change in value you need a converter. - Bulson
  • @Monk unsigned negative buttons are unavailable, but with a sign available. - Draktharon

1 answer 1

You can not use the operator ! in binding. Instead, you need to define a value converter or use a data trigger ( DataTrigger ):

  <Style x:Key="notEnabled" TargetType="Button"> <Style.Triggers> <DataTrigger Binding="{Binding IsChecked}" Value="True"> <Setter Property="IsEnabled" Value="False" /> </DataTrigger> <DataTrigger Binding="{Binding IsChecked}" Value="False"> <Setter Property="IsEnabled" Value="True" /> </DataTrigger> </Style.Triggers> </Style> 

and

  <Button Command="{Binding Activate}" Style="{StaticResource notEnabled}" /> 
  • and where to enter the lines <Style> ... </ Style>? - Draktharon
  • @Draktharon, Where you store resources - Ev_Hyper