views:

285

answers:

2

I am using a WPF TextBox editor to display a decimal value with 2 decimal places.

If i go into the TextBox, and put in the value 27.5, the textbox shows 27.50.

My current mask = "{}{double:5.2}". Is there any way to hide the decimal places if there is no value there? like 52 instead of 52.00?

A: 

In C# and VB you simply make your format string "0.##", so I would imagine you could do that/something similar in WPF.

EDIT: You could also hook in to the TextChanged event and do something like:

TextBox myTextBox = (TextBox)sender;
Double dblTemp = Convert.ToDouble(myTextBox.Text);
myTextBox.Text = dblTemp.ToString("0.##");
smoore
doing that actually makes the number 27.5 turn into 0.27 for some reason... it doesn't seem to function like normal
Doug
A: 

You can try the VIBlend's WPF Editors. You can set the Numeric Editor's DecimalPlaces property to 0 as a solution. Here's a link: http://www.viblend.com/products/net/wpf/controls/free-wpf-controls.aspx The best part is that they are free.

Jane