Joren
Topic Author
Posts: 20
Joined: 12 Nov 2019, 15:33

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

22 May 2024, 13:24

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.
 
User avatar
sfernandez
Site Admin
Posts: 3033
Joined: 22 Dec 2011, 19:20

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

23 May 2024, 10:20

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?
 
Joren
Topic Author
Posts: 20
Joined: 12 Nov 2019, 15:33

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

23 May 2024, 16:01

Ah yes, that does work. Thanks!

Who is online

Users browsing this forum: No registered users and 8 guests