WPF 绑定 StringFormat 语法 [英] WPF binding StringFormat syntax
本文介绍了WPF 绑定 StringFormat 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 WPF 窗口中有条件地格式化十进制值?
How can I format a decimal value conditionally in a WPF window?
- 值应四舍五入为整数(例如:1,234)
- 当值为 0.00 时,它应显示为单个零.(例如:0)
目前我使用波纹管标记来格式化十进制值,但当值为 0.00 时它显示 00.请帮忙.
Currently I use bellow mark up to format the decimal value, but it displays 00 when the value is 0.00. Please help.
<TextBlock
Grid.Column="6"
Padding="2"
Text="{Binding Path=TotalAwardsExpended, StringFormat='{}{0:0,0}'}" />
推荐答案
额外的 0 来自冒号后的 0.
The extra 0 comes from the 0 after the colon.
相反,请尝试 {}{0:#,0}
.
来自 关于自定义数字字符串格式的 MSDN 文档(强调添加):
"0" |零占位符 |如果存在,则用相应的数字替换零;否则,结果字符串中会出现零.
"0" | Zero placeholder | Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.
这篇关于WPF 绑定 StringFormat 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文