【问题标题】:StringFormat with value zero值为零的 StringFormat
【发布时间】:2013-07-11 13:20:45
【问题描述】:

我正在使用componentart 开发一个 wpf 应用程序我有一个这样的文本块

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

如您所见,我的 StringFormat 在数字后放了一个 '%' 符号,但如果我的数据是 0.0(我在后面的代码中填充组件,我的变量是双精度数)我得到“%”,但我想要要获得“0%”,我该怎么做?

【问题讨论】:

    标签: wpf xaml textblock string-formatting componentart


    【解决方案1】:

    您可以使用不同的StringFormat。而不是0:# 而是0:0

    <TextBlock FontSize="28" Text="{Binding Path=MyDouble, StringFormat=\{0:0\\%\}}" Foreground="Black"/>
    

    引用MSDN:

    #:如果“#”符号存在,则将其替换为对应的数字;否则,结果字符串中不会出现数字。

    0:如果有 1,则将 0 替换为对应的数字;否则,结果字符串中将出现零。

    【讨论】:

      猜你喜欢
      • 2013-10-23
      • 2018-02-12
      • 1970-01-01
      • 2015-08-28
      • 2011-04-13
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      相关资源
      最近更新 更多