This project has moved. For the latest updates, please go here.

A suggestion regarding NumericUpDown

Nov 9, 2010 at 10:23 AM

TryParseInt() sets result to the prior Value if input text is not a number. It would be nice to do it if the input is out of bounds as well. For example,

 protected override double ParseValue(string text) {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(CultureInfo.CurrentCulture);
            double result;
            if (text.Contains(info.PercentSymbol))
                result = TryParcePercent(text, info);
                result = TryParceDouble(text, info);
            return CheckBounds(result);
        private double CheckBounds(double number) {
            double result = number;
            if (number < Minimum || number > Maximum) {
                //the input is out of bounds; now lets reset our value, text, and the text in the textbox
                result = Value;
                TextBox.Text = Text = FormatValue();
            return result;

In fact, ParseValue() performs a partial input validation. It would be nice to to allow to use the existing validation schemes. Maybe, you could add an additional DependencyProperty IsValidationUsed, and if it set true, allow an user to do her own validation.

Thanks a lot,


Nov 9, 2010 at 1:57 PM

That is actually a great idea.  I completely overlooked that validation check.  I could also provide an OnValueParcing event so the user can provide their own validation as well.  Thanks.

Nov 9, 2010 at 1:59 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.