Page 1 of 1

Invert Bool Binding

Posted: 11 Aug 2026, 18:48
by BenJo
Hey, what's the best way to invert a bool binding with Studio?
<Button IsEnabled="{Binding Path=bDisabled}"/> <!--(want !bDisabled)-->

You can use DataTriggers to set the property, or would having a converter in Studio be useful, perhaps?

Re: Invert Bool Binding

Posted: 13 Aug 2026, 12:35
by jsantos
I think a converter is the best solution here. I have added BoolInvertConverter to the toolkit. It will be available in the next release candidate of 4.0.
////////////////////////////////////////////////////////////////////////////////////////////////////
bool BoolInvertConverter::TryConvert(BaseComponent* value, const Type*, BaseComponent*,
    Ptr<BaseComponent>& result)
{
    if (Boxing::CanUnbox<bool>(value))
    {
        bool currentValue = Boxing::Unbox<bool>(value);
        result.Reset(Boxing::Box(!currentValue));
        return true;
    }

    return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
bool BoolInvertConverter::TryConvertBack(BaseComponent* value, const Type*, BaseComponent*,
    Ptr<BaseComponent>& result)
{
    if (Boxing::CanUnbox<bool>(value))
    {
        bool currentValue = Boxing::Unbox<bool>(value);
        result.Reset(Boxing::Box(!currentValue));
        return true;
    }

    return false;
}

Re: Invert Bool Binding

Posted: 13 Aug 2026, 13:34
by BenJo
Brilliant! Thanks for that, it will come in handy