New to Telerik UI for WPF? Start a free 30-day trial
RadNumericUpDown Validation Using IDataErrorInfo Interface
Updated on Sep 15, 2025
Environment
| Product Version | 2022.3.1109 |
| Product | RadNumericUpDown for WPF |
Description
How to validate the Value property of the RadNumericUpDown control on custom criteria.
Solution
To achieve this functionality, you can implement the IDataErrorInfo interface in your view model.
Implementing IDataErrorInfo interface
C#
public class NumericUpDownViewModel : ViewModelBase, IDataErrorInfo
{
private double numericUpDownValue;
public NumericUpDownViewModel()
{
this.NumericUpDownValue = -5;
}
public double NumericUpDownValue
{
get { return this.numericUpDownValue; }
set
{
this.numericUpDownValue = value;
this.OnPropertyChanged(nameof(this.NumericUpDownValue));
}
}
public string Error
{
get { return this[string.Empty]; }
}
public string this[string name]
{
get
{
string result = null;
if (name == "NumericUpDownValue")
{
return this.ValidateValue();
}
return result;
}
}
private string ValidateValue()
{
if (this.NumericUpDownValue < 0)
{
return "Value cannot be a negative number";
}
return null;
}
}Binding the Value property of RadNumericUpDown
XAML
<telerik:RadNumericUpDown Value="{Binding NumericUpDownValue, Mode=TwoWay, ValidatesOnDataErrors=True}" UpdateValueEvent="PropertyChanged"/>
In order for the RadNumericUpDown control to show its
Validation.ErrorTemplatewhen an error occurs, set theValidatesOnDataErrorsproperty of theBindinginstance to True.
RadNumericUpDown with a validation error and error message
