Page 1 of 1

DataBinding IsChecked on a checkbox with a nullable bool (ThreeState)

Posted: 22 May 2024, 13:24
by Joren
Hey!

I've been trying to databind the IsChecked value on a checkbox using a Nullable<bool>, but no matter which approach I take to set the indeterminate/null value, it seems to switch to false. Setting {x:Null} straight in the xaml does seem to work.

As far as I can tell, there is no way to directly use a Nullable<bool> in NsProp, so a boxing method would be required. I tried these variants, but the all end up as false in the xaml:
Noesis::BaseComponent* TUIOverviewMapHUDVM::GetAllFiltersEnabled1() const
{
  return Noesis::Boxing::Box<Noesis::Nullable<bool>>(Noesis::Nullable<bool>());
}

Noesis::BaseComponent* TUIOverviewMapHUDVM::GetAllFiltersEnabled2() const
{
  return Noesis::Boxing::Box<Noesis::Nullable<bool>>(nullptr);
}

Noesis::BaseComponent* TUIOverviewMapHUDVM::GetAllFiltersEnabled3() const
{
  return nullptr;
}
So yeah, I'm a bit lost on how to properly implement this.

Re: DataBinding IsChecked on a checkbox with a nullable bool (ThreeState)

Posted: 23 May 2024, 10:20
by sfernandez
Hello, exposing a Nullable<bool> property is working fine like this:
const Nullable<bool>& GetValue() const { return _value; }
void SetValue(const Nullable<bool>& v)
{
    if (_value != v)
    {
        _value = v;
        OnPropertyChanged("Value");
    }
}
...
    
NsProp("Value", &ViewModel::GetValue, &ViewModel::SetValue)
You can set the _value just assigning nullptr or true/false.

Could you try that?

Re: DataBinding IsChecked on a checkbox with a nullable bool (ThreeState)

Posted: 23 May 2024, 16:01
by Joren
Ah yes, that does work. Thanks!