Telerik Forums
UI for WPF Forum
2 answers
36 views

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!

Motti
Top achievements
Rank 1
Iron
 updated answer on 05 May 2025
0 answers
18 views

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?

 

Bradley
Top achievements
Rank 2
Iron
Iron
Iron
 asked on 10 Apr 2025
1 answer
368 views

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.

1 answer
90 views
I have a simple NumericUpDown control showing milliseconds.  I use a 'ms' custom unit to show alongside the number. 

<tk:RadNumericUpDown  Width="150"  Height="50"
    Value="{Binding Exposure}"
    IsInteger="True"
    CustomUnit="ms"/>

It looks good but as soon as hit the + or - key, the 'ms' disappears and I have just a number.  This is because hitting +/- gives keyboard focus to the edit box -- activates the cursor in there and all that.    Once I click somewhere else focus leaves the edit box, the 'ms' re-appears.

Is there a property or some simple way that would let me prevent this behavior?   I want +/- to just change the number without grabbing the keyboard focus.  

Note that I do still want the number to be user-editable if they actually go to the trouble of clicking directly in the edit box itself.  I just want to stop +/- from doing that for me.
Dimitar
Telerik team
 answered on 09 May 2024
0 answers
107 views

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.

 

Dooly
Top achievements
Rank 1
Iron
 asked on 25 Mar 2024
2 answers
79 views

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

Wael
Top achievements
Rank 1
Iron
 answered on 27 Nov 2023
1 answer
123 views

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

Dinko
Telerik team
 answered on 01 Nov 2023
1 answer
177 views

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.

Stenly
Telerik team
 answered on 20 Sep 2023
0 answers
271 views

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?

alex
Top achievements
Rank 2
Bronze
Iron
Iron
 updated question on 16 Sep 2023
1 answer
85 views
I have a RadContextMenu (for an object on a canvas).  It works well. 
I added a NumericUpDown Control to it. 
When I open the menu, If I click the + or - button on the control first, it works fine.   
But if I click directly in the edit box of the control just after opening the menu, then the menu immediately closes.

If I open the menu, first click either the + or - and THEN click inside the edit control, then the menu stays open.

Is there a setting I can change to prevent the menu from immediately closing?

I have attached a small sample that illustrates the issue.  Run the app, right click on the shape and then immediately left click on the text-box portion of the Numeric Up Down.  The Menu will close.  But click on the +/- buttons first and it works.
Martin Ivanov
Telerik team
 answered on 11 Aug 2023
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?