@@ -26,28 +26,27 @@ public static class ScrollViewerHelper
2626 typeof ( ScrollViewerHelper ) ,
2727 new PropertyMetadata ( 1.0 ) ) ;
2828
29- public static bool GetShiftWheelScrollsHorizontally ( UIElement element )
29+ public static bool GetShiftWheelScrollsHorizontally ( DependencyObject obj )
3030 {
31- return ( bool ) element . GetValue ( ShiftWheelScrollsHorizontallyProperty ) ;
31+ return ( bool ) obj . GetValue ( ShiftWheelScrollsHorizontallyProperty ) ;
3232 }
3333
34- public static double GetShiftWheelScrollSpeed ( UIElement element )
34+ public static double GetShiftWheelScrollSpeed ( DependencyObject obj )
3535 {
36- return ( double ) element . GetValue ( ShiftWheelScrollSpeedProperty ) ;
36+ return ( double ) obj . GetValue ( ShiftWheelScrollSpeedProperty ) ;
3737 }
3838
39- public static void SetShiftWheelScrollsHorizontally ( UIElement element , bool value )
39+ public static void SetShiftWheelScrollsHorizontally ( DependencyObject obj , bool value )
4040 {
41- element . SetValue ( ShiftWheelScrollsHorizontallyProperty , value ) ;
41+ obj . SetValue ( ShiftWheelScrollsHorizontallyProperty , value ) ;
4242 }
4343
44- // 默认滚动速率为 1.0
45- public static void SetShiftWheelScrollSpeed ( UIElement element , double value )
44+ public static void SetShiftWheelScrollSpeed ( DependencyObject obj , double value )
4645 {
47- element . SetValue ( ShiftWheelScrollSpeedProperty , value ) ;
46+ obj . SetValue ( ShiftWheelScrollSpeedProperty , value ) ;
4847 }
4948
50- private static void OnPreviewMouseWheel ( object sender , MouseWheelEventArgs args )
49+ private static void OnPreviewMouseWheel ( object sender , MouseWheelEventArgs e )
5150 {
5251 if ( Keyboard . Modifiers != ModifierKeys . Shift )
5352 {
@@ -67,27 +66,27 @@ private static void OnPreviewMouseWheel(object sender, MouseWheelEventArgs args)
6766 }
6867
6968 double scrollSpeed = GetShiftWheelScrollSpeed ( d ) ;
70- double offset = scrollSpeed * ( args . Delta > 0 ? - 1 : 1 ) ;
69+ double offset = scrollSpeed * ( e . Delta > 0 ? - 1 : 1 ) ;
7170
7271 scrollViewer . ScrollToHorizontalOffset ( scrollViewer . HorizontalOffset + ( offset * 48 ) ) ;
7372
74- args . Handled = true ;
73+ e . Handled = true ;
7574 }
7675
7776 private static void UseHorizontalScrollingChangedCallback ( DependencyObject d , DependencyPropertyChangedEventArgs e )
7877 {
79- if ( d is not UIElement element )
78+ if ( d is not UIElement uiElement )
8079 {
8180 throw new Exception ( "Attached property must be used with UIElement." ) ;
8281 }
8382
8483 if ( ( bool ) e . NewValue )
8584 {
86- element . PreviewMouseWheel += OnPreviewMouseWheel ;
85+ uiElement . PreviewMouseWheel += OnPreviewMouseWheel ;
8786 }
8887 else
8988 {
90- element . PreviewMouseWheel -= OnPreviewMouseWheel ;
89+ uiElement . PreviewMouseWheel -= OnPreviewMouseWheel ;
9190 }
9291 }
9392}
0 commit comments