Hi guys,
I have a XAML page with a label which Text property is binding with a ViewModel property named SALDO.
I want to see the label's TextColor Red when the value from SALDO is <0.
I have tried this, there is no compilation error, but the TextColor never change.
<Label Style="{StaticResource TextoGeneral}" Text="{Binding Saldo, StringFormat='{0:C0}'}"> <Label.Triggers> <DataTrigger TargetType="Label" Binding="{Binding Saldo}" Value="<0"> <Setter Property="TextColor" Value="Red" /> </DataTrigger> </Label.Triggers> </Label>
Any idea?
Tanks
Posts
@Pino13
You can't put in calculation in a condition. Its boolean: Either the condition is true or false.
for calculation you'll have to make a
Converter
to do the math then return true or false.@ClintStLaurent
The calculation for SALDO is in the ViewModel .
The boolean trigger is "<0" isnt it?
@Pino13
No. "Is less than 0" is a calculation to be evaluated. Something either is 0 or is not 0. That's boolean.
You can't enter a formula in a string and expect the math to be evaluated by magic.
You can't set a label to "5 + 4 + 6 +8" and expect it to display "23" Just doesn't work that way.
Same here "<3" requires an evaluation calculation to be performed. That requires executable code in a C#
Converter
. It is not done in XAML markup.Just like you can't set
Margin = "5 + 6"
and expect a margin of 11.@ClintStLaurent
Ok, got it.
Im gonna try something based on your explanation and ill be back.
Tanks !
Now Im doing this on ViewModel
and this on XAML
Still no change on TextColor
Look at this working example as a template: