WPF:{:F2 0}文本框用的StringFormat = {}绑定。不显示为零的
我的对象绑定到一个文本框与下面的XAML代码:
I am binding an object to a TextBox with the following XAML:
<文本框名称=MyTextBox文本={绑定路径= myvalue的,模式=双向,的StringFormat = {} {0:F2}}/>
当然,当我绑定一个新的对象(值都仍为零)的Text属性设置为 0.00
。我有几个这样的文本框,这使得它繁琐进入一个新的前删除的每个值。
Naturally when I bind a new object (which values are all still zero) the Text property is set to 0.00
. I have several of these TextBoxes, which makes it tedious to delete every value before entering a new one.
目前我使用的 Window_Loaded 方法,这些盒子的那一刻href=\"http://stackoverflow.com/questions/974598/find-all-controls-in-wpf-window-by-type\">FindVisualChildren方法。
At the moment I'm clearing these boxes in the Window_Loaded
method using the FindVisualChildren method.
我就觉得笨重,但。是否有这样做的一个非常简洁的方式?
It just feels clunky though. Is there a neat way of doing this?
请尝试以下操作:
的StringFormat = {} {0:###}
这会格式化到小数点后两位,并不会显示为零。
It will format to two decimal places and won't show zeroes.