I'm looking for a generic solution for handling a common issue with RadNumericUpDown. When binding the Value property to a double (non-nullable) and the user clears the input (e.g., with Backspace), the control throws a "value cannot be converted" error.
I'm aware that changing the bound property to a double? would resolve this, but in my case, this is not feasible across the entire application due to the extensive refactoring it would require in legacy code.
As a senior WPF developer, I prefer generic solutions that can be applied globally—such as using an attached property via styles—so the fix can be inherited by all RadNumericUpDown instances.
I've considered using FallbackValue or TargetNullValue, but these aren't suitable as they require changes to each individual binding and would assign a default value, which is not ideal.
Since the value in the ViewModel doesn't actually change when the conversion fails, it seems reasonable to simply suppress the error and let the control revert to the source value.
Is there a way to implement an attached property that can detect this conversion failure and handle it gracefully—possibly by resetting the control’s value to the bound property from the DataContext?
Any suggestions or sample code would be greatly appreciated.
Thanks!
This should be trivial, but.... I see an old question about this at HorizontalContentAlignment doesn't work in UI for WPF | Telerik Forums. When I download the sample, it works as advertised, even if I upgrade to the latest. However, in my project I can't seem to get the text to right-justify. This is a direct copy of my XAML:
<telerik:RadNumericUpDown Grid.Row="9" Grid.Column="1" Width="100" NumberDecimalDigits="0" Value="{Binding MyIntField}" HorizontalContentAlignment="Right" />
And yet...
If I inspect the field in the live tree, "HorizontalContentAlignment" shows "Right".
What have I got wrong?
Is there a control in WPF that I can use for numeric input that looks just like a textbox, but doesn't allow anything non-numeric? I've looked at "Masked Input", and don't like the look nor the behavior (e.g. I don't like to see the template, and putting the curser at the beginning of field and hitting a number puts the number in the first digit and fills the rest with zeroes - nothing like a TextBox). I've also looked at the "Numeric UpDown", but haven't found a simple example that looks like a TextBox - all the examples show with the up and down arrows, which I don't want. I'm sure it's just a matter of formatting/templating/whatever, but I'm not a UI guy - I just want to drop the control on my form and maybe tweak a few parameters.
I would just use a TextBox bound to an integer, but the problem with that is if the user enters something non-numeric, a conversion exception is thrown, rather than a validation error. At that point the form validates just fine because the backing field hasn't actually changed yet, so the user can, for example, hit [Save] while there are errors shown on the screen, and the [Save] logic thinks all is well.
Any ideas?
Thanks!
Brad.
<tk:RadNumericUpDown Width="150" Height="50"
Value="{Binding Exposure}"
IsInteger="True"
CustomUnit="ms"/>
Hi,
I am trying to change the theme through telerik StyleManager.Theme.
Not apply :
<mynumeric:MyNumeric x:Name="TEST" Margin="-2,0,0,0"
Value="{Binding ViewModel.SerialNumber,Mode=TwoWay}"
ValueFormat="Numeric"
NumberDecimalDigits="0"
Minimum="1" Maximum="9999"
telerik:StyleManager.Theme="{Binding Path=(mainwindowviewmodel:MainWindowViewModel.CurrentTheme),Converter={StaticResource ThemeToTelerikThemeConverter}}"
IsReadOnly="{Binding Path=(mainwindowviewmodel:MainWindowViewModel.IsManagerAccess),Converter={StaticResource InverseBooleanConverter}}"
>
Apply :
<telerik:RadNumericUpDown x:Name="TEST" Margin="-2,0,0,0"
Value="{Binding ViewModel.SerialNumber,Mode=TwoWay}"
ValueFormat="Numeric"
NumberDecimalDigits="0"
Minimum="1" Maximum="9999"
telerik:StyleManager.Theme="{Binding Path=(mainwindowviewmodel:MainWindowViewModel.CurrentTheme),Converter={StaticResource ThemeToTelerikThemeConverter}}"
IsReadOnly="{Binding Path=(mainwindowviewmodel:MainWindowViewModel.IsManagerAccess),Converter={StaticResource InverseBooleanConverter}}"
>
public class MyNumeric : RadNumericUpDown
{
public override string FormatDisplay()
{
if (this.Value.HasValue)
{
return this.Value.Value.ToString("0000");
}
return base.FormatDisplay();
}
public override string FormatEdit()
{
if (this.Value.HasValue)
{
return this.Value.Value.ToString("0000");
}
return base.FormatEdit();
}
}
internal class ThemeToTelerikThemeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!Enum.IsDefined(typeof(Wpf.Ui.Appearance.ThemeType), value))
throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum");
switch (value)
{
case Wpf.Ui.Appearance.ThemeType.Light:
return "Office2019";
case Wpf.Ui.Appearance.ThemeType.Dark:
return "Expression_Dark";
default:
return "Office2019";
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
I'll appreciate any help.
i am trying to custom style RadNumericUpDown control but every time i try to click right and edit control i am losing focus
tried to find the template in documentation to copy , paste and then edit, however i couldn't
can you help with this please?
Best
Dear Telerik Team,
I am using the RadNumericUpDown control for accepting the numeric value. I have made hidden the up and down tick button so it look like simple textbox. The purpose of using this control specific for Distance and Weight values so it can be in any unit of measurement. For example, meter, millimeter, feet, kg, ton etc.
For simple UOM like meter, I can simply set the CustomUnit as "m" and it works fine. But How can I represent the value of 99.11 feet to feet and inch e.g., 99 ft 1 in
So whenever user trying to edit the value, it will be in feet only and once it is edited value will be displayed in feet and inch.
How can I achieve this behavior using RadNumericUpDown control ?
Thanks & Regards,
Hiren Lad
Hello,
I'm using several RadNumericUpDown controls and when the language/region is set to English, as expected they show numbers with dots as decimal separators, which is fine. But when I set any European language/region they still show dots rather than commas. How can I fix this issue?
My code is like the snippet below:
<telerik:RadNumericUpDown Value="{Binding ScaleMin}" HorizontalAlignment="Stretch" Width="120" Margin="5"
VerticalAlignment="Center" SmallChange="0.1" ValueFormat="Numeric" IsEnabled="{Binding IsAvailable}">
<telerik:RadNumericUpDown.NumberFormatInfo>
<global:NumberFormatInfo NumberGroupSeparator="" NumberDecimalDigits="1"/>
</telerik:RadNumericUpDown.NumberFormatInfo>
<telerik:RadNumericUpDown.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="MaxLength" Value="8"/>
</Style>
</telerik:RadNumericUpDown.Resources>
</telerik:RadNumericUpDown>
Thanks,
G.
Hello,
I have a NumericUpDown with the following configuration:
1. NumberDecimalDigits=3
2. Binding to Double property in ViewModel
3. Validation (IDataErrorInfo) between 20-3000.
4. Small change 0.001
5. Big change 0.1
When I write 123.1234, I can see 123.123 in the UI but in the view model, you don't remove the additional digits.
I have the following problems:
1. Sometimes when using arrows up/down or page up/down, the 4 digit is removed. I expected that the snall/large change takes effect without removing any digits because the NumberDecimalDigits shall affect the UI.
2. On grouping/filtering, I want to apply the logic on the UI value instead of the binding value.
For 1234.1234 and 1234.1235 will be created two different groups.
In case that I have a double with 4 digits, but in the UI is configured to N3, I don't want to see two groups with same value in the Header Text. The user will not understand why there are two groups.
How can I configure the RadNumericUpDown to show 3 digits but if there is an error and the number has 4 digits to show 4 digits? (with this solution the user will understand why there is an error if he types 19.9996.
For this value, it will be round 20.000 and mark as error when minimim value 20 is allowed. Showing 4 digits will solve it.
How can I configure the Grouping and Filtering of the RadGridView to consider some double value as N3?