NumericUpDown Unable to style away scroll increment

2 posts, 0 answers
  1. Joe
    Joe avatar
    1 posts
    Member since:
    Oct 2018

    Posted 20 Mar Link to this post

    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

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    908 posts

    Posted 25 Mar Link to this post

    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.
Back to Top