Invert Bool Binding
Hey, what's the best way to invert a bool binding with Studio?
You can use DataTriggers to set the property, or would having a converter in Studio be useful, perhaps?
Code: Select all
<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
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.
Code: Select all
////////////////////////////////////////////////////////////////////////////////////////////////////
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
Brilliant! Thanks for that, it will come in handy
Who is online
Users browsing this forum: Baidu [Spider] and 1 guest