Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide stringformat if data is null

How to hide a stringformat when data is not present.Consider this sample

<TextBlock Text="{Binding Amount, StringFormat=Total: {0:C}}" />

in this case if Amount is null,Then it will show just Total:.How to hide this if Amount is null or empty

like image 862
biju Avatar asked Sep 15 '10 18:09

biju


3 Answers

You either have to implement some sort of value converter (Example) or consider using the TargetNullValue property on the binding (Example)

like image 110
rudigrobler Avatar answered Nov 15 '22 21:11

rudigrobler


"TargetNullValue" is what i was looking for.I ended up with this and it worked like a charm

<TextBlock VerticalAlignment="Top"
             Text="{Binding Path=TotalMonths,
        TargetNullValue={x:Static System:String.Empty},
        StringFormat=Total: {0:C}}" />
like image 25
biju Avatar answered Nov 15 '22 19:11

biju


TargetNullValue=''

Will do also

like image 40
dave Avatar answered Nov 15 '22 20:11

dave