New to Telerik UI for WPF? Download free 30-day trial

How to Disable the Scroll Wheel in RadNumericUpDown

Environment

Product Version 2019.1 318
Product RadNumericUpDown for WPF and Silverlight

Description

How to disable the RadNumericUpDown mouse wheel functionality.

Solution

You can disable the scroll wheel functionality of the RadNumericUpDown control globally by defining an attached behavior.

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); 
                } 
        } 
} 
You can then set this behavior via an implicit style to all instances in your application.

App.xaml

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

See Also

In this article