This is a migrated thread and some comments may be shown as answers.

NumericUpDown Unable to style away scroll increment

1 Answer 176 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 20 Mar 2019, 03:10 PM

While using the RadNumericUpDown control in our product we want a global way to disable the scroll wheel functionality that increases/decreases the value by a given step.

RadMaskedNumericInput is easy...

 

<Setter Property="SpinMode" Value="None" />

 

But I cant find anything for a global style to disable this functionality.

Is there something I might be missing or is there no way in a style to achieve this like there is with the masked numeric input

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 25 Mar 2019, 12:04 PM
Hi Joe,

You can disable the scroll wheel functionality of the RadNumericUpDown control globally by defining an attached behavior and setting it via an implicit style to all instances in your application. Here's what I have in mind:

MouseWheelBehavior.cs:

public class MouseWheelBehavior
{
    public static bool GetIsEnabled(DependencyObject obj)
    {
        return (bool)obj.GetValue(IsEnabledProperty);
    }
 
    public static void SetIsEnabled(DependencyObject obj, bool value)
    {
        obj.SetValue(IsEnabledProperty, value);
    }
     
    public static readonly DependencyProperty IsEnabledProperty =
        DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(MouseWheelBehavior), new PropertyMetadata(true, OnIsEnabledChanged));
 
    private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (!(bool)e.NewValue)
        {
            var upDown = d as RadNumericUpDown;
            upDown.AddHandler(RadNumericUpDown.PreviewMouseWheelEvent, new MouseWheelEventHandler((s, a) => { a.Handled = true; }), true);
        }
    }
}

App.xaml:

<Style TargetType="telerik:RadNumericUpDown">
    <Setter Property="local:MouseWheelBehavior.IsEnabled" Value="False" />
</Style>

Please give this a try and let me know if such an approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
NumericUpDown
Asked by
Joe
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or