StringFormat 值为零 [英] StringFormat with value zero

查看:41
本文介绍了StringFormat 值为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 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 值为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆