How to eliminate trailing 0s in DoubleEditBox

Editors for WPF Forum

Posted 7 years ago by Moondance
Version: 16.1.0632
Avatar

I am using a DoubleEditBox. I am setting the StepValue to 0.1 and its Format to F2.

I would like to be able to eliminate all trailing 0s on commit

So Ok to type 2.30 but on Enter I want it to change to 2.3. And 2.31 needs to remain 2.31 of course.

Is there a way to do that? Maybe a property?

Thank you so much

Comments (5)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I believe our v2017.1 DoubleEditBox supports custom formats where you could set the Format to "#0.0#" and it would effectively do what you want.

However I don't believe custom numeric formats were supported like that in the older 2016.1 version and earlier.  Only standard numeric formats were supported in that version.  That being said, you could set a custom DoubleEditBox.StringValueConverter object or could make a class that inherits DoubleEditBox and override its ConvertToString property.  Either of those might let you programmatically coerce the text result in v2016.1.


Actipro Software Support

Posted 7 years ago by Moondance
Avatar

Ok I am all upgraded to 17.1 now.
I tried to use the format suggested but it seems that I get the same behavior as if I types F1. The trailing zeros are there.
Here is the xaml I used:
<Grid>
<editors:DoubleEditBox Minimum ="3" Maximum="400" CommitTriggers="Default" SmallChange=".1"
Format="#0.0#" Width="80" Height="20" />
</Grid>
</Window>
<!--Format="#0.0#"-->
<!--LargeChange="" WHAT??

Can you help me correct the format please? I am not really understanding how to craete a custom one.

Due to upgrade I now have 2 more issues:
Reaching the Minimum or Maximum in the spinner no longer grays out the arrows up or down (this can be seen even in the samples.
This was the previuos behavior and a good one to keep. How do I get it back?

Finally, typing a value say, lower of the minimum will cause the spinner to go to its minimum value
instaed of going back to its previous or last good value. This, again, can be see in the sample as well and was a problem present
in the previous versions as well (set min= -3, set max=12, type 5 Enter, type 2 enter and the spinner goes to 3 instead of 5.
However previously I was able to fix its behavior by overriding the OnValueCHanging method, but this method no longer exists.
Below if the code I used in the past:

protected override void OnValueChanging(PropertyChangingRoutedEventArgs<double?> e)
{
if (_maskedBox != null && Minimum.HasValue && !string.IsNullOrEmpty(_maskedBox.Text))
{
double textAsDouble;
double.TryParse(_maskedBox.Text, out textAsDouble);
if (textAsDouble < Minimum)
{
e.Cancel = true;
}
}
base.OnValueChanging(e);
}

How can I fix the problem in this version?

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I apologize, the previous sample I gave would have been for if you wanted at minimum one trailing zero and at most two numbers after the decimal.  I believe if you set Format="0.##" then it will basically be 0-2 digits following the decimal, depending on if the trailing digits are zeros or not.

Thank you for letting us know about the spinner buttons not disabling when their extents are reached.  We will look into this.

For the alternate minimum coersion, you could probably it like this:

protected internal override bool TryConvertFromString(string textToConvert, bool canCoerce, out Double? value) {
	if ((canCoerce) && (!string.IsNullOrEmpty(textToConvert))) {
		double textAsDouble;
		if (double.TryParse(textToConvert, out textAsDouble)) {
			if (textAsDouble < Minimum) {
				value = this.IntermediateValue;
				return false;
			}
		}
	}

	return base.TryConvertFromString(textToConvert, canCoerce, out value);
}


Actipro Software Support

Posted 7 years ago by Moondance
Avatar

Thank you for the quick reply.
The custom format works perfectly
The overriden method does not work as well as the old one I had using the OnValueChanging
In fact, to revert to the last good value pressing Enter is no loger sufficient, I seem to have to click with the mouse
outside of the control
For the spinner not looking disabled any more when the constraints are reached, how can I be informed if there is a workaround or a fix?

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

For the custom format comment, can you provide a step by step example so I can follow along and see what you are describing?  Thanks!

For the spinner question, we would post back here.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.