Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide zero values with StringFormat

I made a similar question months ago

In this case I have a textblock like this

<TextBlock FontSize="28" Text="{Binding DataPoint.Y, StringFormat=\{0:0\\%\}}" Foreground="Black">

As you can see, my StringFormat puts a '%' sign after the number, if my data is 0.0 (I fill the component in code behind, my variable is a double) I get "0%"

But now I want to get "" if my text is 0.0

So far I have this:

 Text="{Binding DataPoint.Y, StringFormat=\{0:#.#\\%\}}"

But this retrieves "%", how can I get ""?

like image 984
Naty Bizz Avatar asked Oct 24 '25 01:10

Naty Bizz


1 Answers

None of these worked for simple positive integers. I had a field which would always default to 0. To hide it, but not add any decimals places, I use:

Text="{Binding BuyerNumber, StringFormat=0;;#}"

Hope this helps someone out who is looking for integers only.

like image 127
Michael K Avatar answered Oct 25 '25 21:10

Michael K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!