Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Issue: IntegerUpDown discards input when it includes FormatString formatting [22049]

$
0
0
Precondition: The IntegerUpDown has a FormatString such as "{}0%" or "{}0°".

Repro: In the input box select only the numeric part, such as "10" when "10%" is shown, then enter a new value. The new value is discarded.

I would have liked to workaround this temporarily by handling TextChanged or InputValidationError but this was not possible due to #22017. Instead I had to review IntegerUpDown's implementation and override ConvertTextToValue(). Here is my implementation for reference:

```
public class IntegerUpDown : Xceed.Wpf.Toolkit.IntegerUpDown
{
protected string suffix = "";

public string Suffix
{
get { return suffix; }
set
{
suffix = value ?? "";
FormatString = suffix == null ? "" : ("0" + suffix);
}
}

protected override int? ConvertTextToValue (string text)
{
if (string.IsNullOrEmpty(text))
{
return null;
}

string currentValueText = ConvertValueToText();
if (object.Equals(currentValueText, text))
{
return Value;
}

// skip user supplied suffix
if (!string.IsNullOrEmpty(Suffix) && text.EndsWith(Suffix))
{
text = text.Slice(-Suffix.Length);
}

// if FormatException then caller will keep both text and original
// value and signal validation error
//
int newValue = int.Parse(text, ParsingNumberStyle, CultureInfo);

int maximum = Maximum.HasValue ? Maximum.Value : int.MaxValue;
int minimum = Minimum.HasValue ? Minimum.Value : int.MinValue;
if (ClipValueToMinMax)
{
return MathUtil.Clamp(newValue, minimum, maximum);
}

if (!object.Equals(newValue, DefaultValue) &&
newValue != MathUtil.Clamp(newValue, minimum, maximum))
{
throw new ArgumentOutOfRangeException("Value",
"Value must be between {} and {}".With(minimum, maximum));
}
return newValue;
}
}
```
Comments: ** Comment from web user: BoucherS **

Hi,

This will be fixed in v3.0.
Modifying the numeric part of a NumericUpDown, with a FormatString containing non-numeric characters, won't discard the changes anymore.


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>