我正在用 componentart 开发一个 wpf 应用程序,我有一个这样的文本块
I'm developing a wpf application with componentart I have a textblock like this
<TextBlock FontSize="28" Text="{Binding DataPoint.Y, StringFormat=\{0:#\\%\}}" Foreground="Black">如您所见,我的 StringFormat 在数字后面放了一个 '%' 符号,但是如果我的数据是 0.0(我在后面的代码中填充了组件,我的变量是双精度)我得到了%",但我想要要获得0%",我该怎么做?
As you can see, my StringFormat puts a '%' sign after the number, but if my data is 0.0 (I fill the component in code behind, my variable is a double) I get "%", but I want to get "0%", how can I do this?
推荐答案您可以使用不同的 StringFormat.而不是 0:# 把 0:0:
you can use different StringFormat. Instead of 0:# put 0:0:
<TextBlock FontSize="28" Text="{Binding Path=MyDouble, StringFormat=\{0:0\\%\}}" Foreground="Black"/>引用 MSDN:
#:替换#"如果存在,则带有相应数字的符号;否则,结果字符串中不会出现数字.
#: Replaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.
0:如果有一个,用相应的数字替换零;否则,结果字符串中将出现零.
0: Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.
更多推荐
StringFormat 值为零
发布评论