How to convert number in string using ternary operator and CalcBinding extension for XAML

453 Views Asked by At

I have a TextBlock element and a Quantity (int) property.
I want to convert the value to a string.
The conversion must be like this:

Quantity == 0 ? "" : Quantity

I'm trying to use the CalcBinding extension, but I wasn't able to write the expression with the correct syntax.

<TextBlock TextWrapping="Wrap" Text="{c:Binding '(Quantity == 0 ? "" : Quantity)'}"
           Margin="-32,0,0,0" Height="16"
           HorizontalAlignment="Center" />

The above doesn't work.
I think that the quotes are my problem, but I don't know how to fix it.

1

There are 1 best solutions below

0
On

For those who still wants to know the solution, here it is:

Binding="{c:Binding (IsActive ? \'Yea\' : \'No\')}"/>