开发者

WPF: Textbox Binding with StringFormat={}{0:F2}. Don't show zero's

开发者 https://www.devze.com 2023-01-16 15:00 出处:网络
I am binding an object to a TextBox with the following XAML: <TextBox Name=\"MyTextBox\" Text=\"{Bi开发者_如何转开发nding Path=MyValue, Mode=TwoWay, StringFormat={}{0:F2}}\" />

I am binding an object to a TextBox with the following XAML:

<TextBox Name="MyTextBox" Text="{Bi开发者_如何转开发nding Path=MyValue, Mode=TwoWay, StringFormat={}{0:F2}}" />

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.

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?


Try the following:

StringFormat={}{0:#.##}

It will format to two decimal places and won't show zeroes.

0

精彩评论

暂无评论...
验证码 换一张
取 消