
I have a problem with RadNumericUpDown control. I'm not able to display edge values of double type (e.g. NaN or Infinity). Every time I try to bind to property with these values I've got a Binding error.
Is it even possible to achieve it utilizing RadNumericUpDown?
Thanks!
3 Answers, 1 is accepted
Hello Lukasz,
You can achieve the desired result by utilizing the NullValue property of the RadNumericUpDown control and binding it to a property of your viewmodel. Here's what I have in mind:
public double? Value
{
get
{
return this.value;
}
set
{
this.value = value;
this.RaisePropertyChanged();
if (this.value != null && double.IsNaN(this.value.Value))
{
this.NullValue = "NaN";
}
else if (this.value == double.PositiveInfinity)
{
this.NullValue = "+Inf";
}
else if (this.value == double.NegativeInfinity)
{
this.NullValue = "-Inf";
}
}
}
Attached you can find a small sample project which demonstrates this in action. Please have a look and let me know if this works for you.
Regards,
Dilyan Traykov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Dilyan, thank you for your quickanswear!
I'll let you know whether it's ok or not.
Regards!

Unfortunately, it was not my intention to have these properties within view model, but within the control (by overriding properties or methods). I have thousands of view models when I have to to introduce such a thing, so there is no way to do this by changing view model this way. Am I able to achieve it by creating the new control inheriting from RadNumericUpDown?
I tried to override RadNumericUpDown.FormatDisplay() method, but it does not allow to bind NaN or Inf anyway, so I've got a null value within Value property.
Regards!
Hello Lukasz,
The Value dependency property of the RadNumericUpDown has a ValidateValueCallback which performs the following check:
private static bool IsValidDoubleValue(object value)
{
if (value == null)
return true;
double num = (double)value;
return !DoubleUtil.IsNaN(num) && !double.IsInfinity(num);
}
That is why the NaN and Infinity values cannot be bound.
Indeed, you may be able to achieve the desired result by inheriting from RadNumericUpDown and exposing additional properties. You may also need to edit the control template of the new control, however, to achieve the desired result.
For NaN/+Inf/-Inf etc on view model side, I just want to have the same value within control. Currently I'm not able to do this in RadNumericUpDown.
Example:
- vm: NaN -> control: NaN
- vm: +Inf -> control: +Inf
etc.
public class ViewModel : INotifyPropertyChanged
{
public double? Value {get; set;}
}