Skip to content

Commit cab6fb0

Browse files
committed
enhance: add IsHoverResizingEnabled prop.
1 parent 08f2fbf commit cab6fb0

File tree

4 files changed

+194
-35
lines changed

4 files changed

+194
-35
lines changed

src/Net_40/HandyControl_Net_40/Themes/Theme.xaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,27 @@
20102010
</ControlTemplate>
20112011
</Setter.Value>
20122012
</Setter>
2013+
<Style.Triggers>
2014+
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
2015+
<Setter Property="Template">
2016+
<Setter.Value>
2017+
<ControlTemplate TargetType="Thumb">
2018+
<Border Width="{TemplateBinding Width}" Background="Transparent">
2019+
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" HorizontalAlignment="Right" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="8" Fill="{TemplateBinding Background}" />
2020+
</Border>
2021+
<ControlTemplate.Triggers>
2022+
<Trigger Property="IsMouseOver" Value="true">
2023+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
2024+
</Trigger>
2025+
<Trigger Property="IsDragging" Value="true">
2026+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
2027+
</Trigger>
2028+
</ControlTemplate.Triggers>
2029+
</ControlTemplate>
2030+
</Setter.Value>
2031+
</Setter>
2032+
</Trigger>
2033+
</Style.Triggers>
20132034
</Style>
20142035
<Style x:Key="ScrollBarBaseThumbHorizontal" TargetType="Thumb">
20152036
<Setter Property="OverridesDefaultStyle" Value="true" />
@@ -2073,6 +2094,27 @@
20732094
</ControlTemplate>
20742095
</Setter.Value>
20752096
</Setter>
2097+
<Style.Triggers>
2098+
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
2099+
<Setter Property="Template">
2100+
<Setter.Value>
2101+
<ControlTemplate TargetType="Thumb">
2102+
<Border Height="{TemplateBinding Height}" Background="Transparent">
2103+
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" VerticalAlignment="Bottom" Height="8" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}" />
2104+
</Border>
2105+
<ControlTemplate.Triggers>
2106+
<Trigger Property="IsMouseOver" Value="true">
2107+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
2108+
</Trigger>
2109+
<Trigger Property="IsDragging" Value="true">
2110+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
2111+
</Trigger>
2112+
</ControlTemplate.Triggers>
2113+
</ControlTemplate>
2114+
</Setter.Value>
2115+
</Setter>
2116+
</Trigger>
2117+
</Style.Triggers>
20762118
</Style>
20772119
<Style x:Key="ScrollBarBaseStyle" TargetType="ScrollBar">
20782120
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />

src/Shared/HandyControl_Shared/Controls/Attach/ScrollViewerAttach.cs

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,87 @@ namespace HandyControl.Controls;
1010
public 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
}

src/Shared/HandyControl_Shared/Themes/Styles/Base/ScrollViewerBaseStyle.xaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@
7878
</ControlTemplate>
7979
</Setter.Value>
8080
</Setter>
81+
<Style.Triggers>
82+
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
83+
<Setter Property="Template">
84+
<Setter.Value>
85+
<ControlTemplate TargetType="Thumb">
86+
<Border Width="{TemplateBinding Width}" Background="Transparent">
87+
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" HorizontalAlignment="Right" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="8" Fill="{TemplateBinding Background}"/>
88+
</Border>
89+
<ControlTemplate.Triggers>
90+
<Trigger Property="IsMouseOver" Value="true">
91+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}"/>
92+
</Trigger>
93+
<Trigger Property="IsDragging" Value="true">
94+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}"/>
95+
</Trigger>
96+
</ControlTemplate.Triggers>
97+
</ControlTemplate>
98+
</Setter.Value>
99+
</Setter>
100+
</Trigger>
101+
</Style.Triggers>
81102
</Style>
82103

83104
<Style x:Key="ScrollBarBaseThumbHorizontal" TargetType="Thumb">
@@ -142,6 +163,27 @@
142163
</ControlTemplate>
143164
</Setter.Value>
144165
</Setter>
166+
<Style.Triggers>
167+
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
168+
<Setter Property="Template">
169+
<Setter.Value>
170+
<ControlTemplate TargetType="Thumb">
171+
<Border Height="{TemplateBinding Height}" Background="Transparent">
172+
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" VerticalAlignment="Bottom" Height="8" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}"/>
173+
</Border>
174+
<ControlTemplate.Triggers>
175+
<Trigger Property="IsMouseOver" Value="true">
176+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}"/>
177+
</Trigger>
178+
<Trigger Property="IsDragging" Value="true">
179+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}"/>
180+
</Trigger>
181+
</ControlTemplate.Triggers>
182+
</ControlTemplate>
183+
</Setter.Value>
184+
</Setter>
185+
</Trigger>
186+
</Style.Triggers>
145187
</Style>
146188

147189
<Style x:Key="ScrollBarBaseStyle" TargetType="ScrollBar">

src/Shared/HandyControl_Shared/Themes/Theme.xaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,27 @@
20102010
</ControlTemplate>
20112011
</Setter.Value>
20122012
</Setter>
2013+
<Style.Triggers>
2014+
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
2015+
<Setter Property="Template">
2016+
<Setter.Value>
2017+
<ControlTemplate TargetType="Thumb">
2018+
<Border Width="{TemplateBinding Width}" Background="Transparent">
2019+
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" HorizontalAlignment="Right" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="8" Fill="{TemplateBinding Background}" />
2020+
</Border>
2021+
<ControlTemplate.Triggers>
2022+
<Trigger Property="IsMouseOver" Value="true">
2023+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
2024+
</Trigger>
2025+
<Trigger Property="IsDragging" Value="true">
2026+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
2027+
</Trigger>
2028+
</ControlTemplate.Triggers>
2029+
</ControlTemplate>
2030+
</Setter.Value>
2031+
</Setter>
2032+
</Trigger>
2033+
</Style.Triggers>
20132034
</Style>
20142035
<Style x:Key="ScrollBarBaseThumbHorizontal" TargetType="Thumb">
20152036
<Setter Property="OverridesDefaultStyle" Value="true" />
@@ -2073,6 +2094,27 @@
20732094
</ControlTemplate>
20742095
</Setter.Value>
20752096
</Setter>
2097+
<Style.Triggers>
2098+
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
2099+
<Setter Property="Template">
2100+
<Setter.Value>
2101+
<ControlTemplate TargetType="Thumb">
2102+
<Border Height="{TemplateBinding Height}" Background="Transparent">
2103+
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" VerticalAlignment="Bottom" Height="8" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}" />
2104+
</Border>
2105+
<ControlTemplate.Triggers>
2106+
<Trigger Property="IsMouseOver" Value="true">
2107+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
2108+
</Trigger>
2109+
<Trigger Property="IsDragging" Value="true">
2110+
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
2111+
</Trigger>
2112+
</ControlTemplate.Triggers>
2113+
</ControlTemplate>
2114+
</Setter.Value>
2115+
</Setter>
2116+
</Trigger>
2117+
</Style.Triggers>
20762118
</Style>
20772119
<Style x:Key="ScrollBarBaseStyle" TargetType="ScrollBar">
20782120
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />

0 commit comments

Comments
 (0)