This worked for me
{0:#\\%;0:#;#}
문제
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 ""?
해결책 2
This worked for me
{0:#\\%;0:#;#}
다른 팁
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.
Use Custom Numeric Format Strings. Specifically, see the ";" Section Separator.
Using {0:#.#\\%;-#.#\\%;}
will give you the desired output, I believe.