@@ -10,68 +10,87 @@ namespace HandyControl.Controls;
1010public class ScrollViewerAttach
1111{
1212 public static readonly DependencyProperty AutoHideProperty = DependencyProperty . RegisterAttached (
13- "AutoHide" , typeof ( bool ) , typeof ( ScrollViewerAttach ) , new FrameworkPropertyMetadata ( ValueBoxes . TrueBox , FrameworkPropertyMetadataOptions . Inherits ) ) ;
13+ "AutoHide" , typeof ( bool ) , typeof ( ScrollViewerAttach ) ,
14+ new FrameworkPropertyMetadata ( ValueBoxes . TrueBox , FrameworkPropertyMetadataOptions . Inherits ) ) ;
15+
16+ public static readonly DependencyProperty OrientationProperty = DependencyProperty . RegisterAttached (
17+ "Orientation" , typeof ( Orientation ) , typeof ( ScrollViewerAttach ) ,
18+ new FrameworkPropertyMetadata ( ValueBoxes . VerticalBox , FrameworkPropertyMetadataOptions . Inherits ,
19+ OnOrientationChanged ) ) ;
20+
21+ public static readonly DependencyProperty IsDisabledProperty = DependencyProperty . RegisterAttached (
22+ "IsDisabled" , typeof ( bool ) , typeof ( ScrollViewerAttach ) ,
23+ new PropertyMetadata ( ValueBoxes . FalseBox , OnIsDisabledChanged ) ) ;
24+
25+ public static readonly DependencyProperty IsHoverResizingEnabledProperty = DependencyProperty . RegisterAttached (
26+ "IsHoverResizingEnabled" , typeof ( bool ) , typeof ( ScrollViewerAttach ) ,
27+ new FrameworkPropertyMetadata ( ValueBoxes . TrueBox , FrameworkPropertyMetadataOptions . Inherits ) ) ;
1428
1529 public static void SetAutoHide ( DependencyObject element , bool value )
16- => element . SetValue ( AutoHideProperty , ValueBoxes . BooleanBox ( value ) ) ;
30+ {
31+ element . SetValue ( AutoHideProperty , ValueBoxes . BooleanBox ( value ) ) ;
32+ }
1733
1834 public static bool GetAutoHide ( DependencyObject element )
19- => ( bool ) element . GetValue ( AutoHideProperty ) ;
20-
21- public static readonly DependencyProperty OrientationProperty = DependencyProperty . RegisterAttached (
22- "Orientation" , typeof ( Orientation ) , typeof ( ScrollViewerAttach ) , new FrameworkPropertyMetadata ( ValueBoxes . VerticalBox , FrameworkPropertyMetadataOptions . Inherits , OnOrientationChanged ) ) ;
35+ {
36+ return ( bool ) element . GetValue ( AutoHideProperty ) ;
37+ }
2338
2439 private static void OnOrientationChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
2540 {
26- if ( d is ScrollViewer )
27- {
28- return ;
29- }
30-
31- if ( d is System . Windows . Controls . ScrollViewer scrollViewer )
41+ switch ( d )
3242 {
33- if ( ( Orientation ) e . NewValue == Orientation . Horizontal )
34- {
43+ case ScrollViewer :
44+ return ;
45+ case System . Windows . Controls . ScrollViewer scrollViewer
46+ when ( Orientation ) e . NewValue == Orientation . Horizontal :
3547 scrollViewer . PreviewMouseWheel += ScrollViewerPreviewMouseWheel ;
36- }
37- else
38- {
48+ break ;
49+ case System . Windows . Controls . ScrollViewer scrollViewer :
3950 scrollViewer . PreviewMouseWheel -= ScrollViewerPreviewMouseWheel ;
40- }
51+ break ;
4152 }
4253
54+ return ;
55+
4356 void ScrollViewerPreviewMouseWheel ( object sender , MouseWheelEventArgs args )
4457 {
4558 var scrollViewerNative = ( System . Windows . Controls . ScrollViewer ) sender ;
46- scrollViewerNative . ScrollToHorizontalOffset ( Math . Min ( Math . Max ( 0 , scrollViewerNative . HorizontalOffset - args . Delta ) , scrollViewerNative . ScrollableWidth ) ) ;
59+ scrollViewerNative . ScrollToHorizontalOffset ( Math . Min (
60+ Math . Max ( 0 , scrollViewerNative . HorizontalOffset - args . Delta ) , scrollViewerNative . ScrollableWidth ) ) ;
4761
4862 args . Handled = true ;
4963 }
5064 }
5165
5266 public static void SetOrientation ( DependencyObject element , Orientation value )
53- => element . SetValue ( OrientationProperty , ValueBoxes . OrientationBox ( value ) ) ;
67+ {
68+ element . SetValue ( OrientationProperty , ValueBoxes . OrientationBox ( value ) ) ;
69+ }
5470
5571 public static Orientation GetOrientation ( DependencyObject element )
56- => ( Orientation ) element . GetValue ( OrientationProperty ) ;
57-
58- public static readonly DependencyProperty IsDisabledProperty = DependencyProperty . RegisterAttached (
59- "IsDisabled" , typeof ( bool ) , typeof ( ScrollViewerAttach ) , new PropertyMetadata ( ValueBoxes . FalseBox , OnIsDisabledChanged ) ) ;
72+ {
73+ return ( Orientation ) element . GetValue ( OrientationProperty ) ;
74+ }
6075
6176 private static void OnIsDisabledChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
6277 {
63- if ( d is UIElement element )
78+ if ( d is not UIElement element )
6479 {
65- if ( ( bool ) e . NewValue )
66- {
67- element . PreviewMouseWheel += ScrollViewerPreviewMouseWheel ;
68- }
69- else
70- {
71- element . PreviewMouseWheel -= ScrollViewerPreviewMouseWheel ;
72- }
80+ return ;
81+ }
82+
83+ if ( ( bool ) e . NewValue )
84+ {
85+ element . PreviewMouseWheel += ScrollViewerPreviewMouseWheel ;
86+ }
87+ else
88+ {
89+ element . PreviewMouseWheel -= ScrollViewerPreviewMouseWheel ;
7390 }
7491
92+ return ;
93+
7594 void ScrollViewerPreviewMouseWheel ( object sender , MouseWheelEventArgs args )
7695 {
7796 if ( args . Handled )
@@ -93,8 +112,22 @@ void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs args)
93112 }
94113
95114 public static void SetIsDisabled ( DependencyObject element , bool value )
96- => element . SetValue ( IsDisabledProperty , ValueBoxes . BooleanBox ( value ) ) ;
115+ {
116+ element . SetValue ( IsDisabledProperty , ValueBoxes . BooleanBox ( value ) ) ;
117+ }
97118
98119 public static bool GetIsDisabled ( DependencyObject element )
99- => ( bool ) element . GetValue ( IsDisabledProperty ) ;
120+ {
121+ return ( bool ) element . GetValue ( IsDisabledProperty ) ;
122+ }
123+
124+ public static void SetIsHoverResizingEnabled ( DependencyObject d , bool value )
125+ {
126+ d . SetValue ( IsHoverResizingEnabledProperty , value ) ;
127+ }
128+
129+ public static bool GetIsHoverResizingEnabled ( DependencyObject d )
130+ {
131+ return ( bool ) d . GetValue ( IsHoverResizingEnabledProperty ) ;
132+ }
100133}
0 commit comments