0

I have many checkbox binding nullable bool values and when I press on the control, if it's set to null, I have to press twice to get true. Is it possible to have true as the first value or false as default when I have null for all the checkbox, for example with a style?

I've tried with this before, and it works:

<CheckBox  IsThreeState="False" IsChecked="{Binding MY_NULLABLE_PROPERTY, TargetNullValue=false}"/>

but I would like a generic solution for each control

EDITED:

I need to handle the problem for checkbox inside datagrid as well

  • You can add one or more ResourceDictionaries containing global `Styles` to your `App.xaml` as described for example here https://stackoverflow.com/questions/3569974/wpf-global-style – Stefan Wuebbe Jun 28 '22 at 11:49
  • Yes, my idea was to use a global style, but I need to set the false value only when IsCheched is null – elisa amato Jun 28 '22 at 14:36
  • Yes, my bad not to have seen you mentioning Styles already. This following SO thread seems to cover your first option: _" Is it possible to have true as the first value"_: https://stackoverflow.com/questions/5313998/make-checkbox-bound-to-nullable-bool-transition-from-null-to-true – Stefan Wuebbe Jun 28 '22 at 18:31
  • It only partially solves the problem. However, it is necessary to modify all the checkboxes of the project or create a custom checkbox to replace all the controls already in use. But there is a further problem: it does not work with checkboxes inside the datagrid – elisa amato Jun 30 '22 at 09:38

0 Answers0