enhance: add IsHoverResizingEnabled prop.

This commit is contained in:
NaBian committed 2025-05-07 14:51:56 +08:00
1 parent 08f2fbfad3
commit cab6fb0a58
4 files changed
+197 -38

No files matched your search

@@ -2010,6 +2010,27 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Width="{TemplateBinding Width}" Background="Transparent">
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" HorizontalAlignment="Right" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="8" Fill="{TemplateBinding Background}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarBaseThumbHorizontal" TargetType="Thumb">
<Setter Property="OverridesDefaultStyle" Value="true" />
@@ -2073,6 +2094,27 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Height="{TemplateBinding Height}" Background="Transparent">
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" VerticalAlignment="Bottom" Height="8" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarBaseStyle" TargetType="ScrollBar">
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
@@ -10,68 +10,87 @@ namespace HandyControl.Controls;
public class ScrollViewerAttach
{
public static readonly DependencyProperty AutoHideProperty = DependencyProperty.RegisterAttached(
"AutoHide", typeof(bool), typeof(ScrollViewerAttach), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits));
public static void SetAutoHide(DependencyObject element, bool value)
=> element.SetValue(AutoHideProperty, ValueBoxes.BooleanBox(value));
public static bool GetAutoHide(DependencyObject element)
=> (bool) element.GetValue(AutoHideProperty);
"AutoHide", typeof(bool), typeof(ScrollViewerAttach),
new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits));
public static readonly DependencyProperty OrientationProperty = DependencyProperty.RegisterAttached(
"Orientation", typeof(Orientation), typeof(ScrollViewerAttach), new FrameworkPropertyMetadata(ValueBoxes.VerticalBox, FrameworkPropertyMetadataOptions.Inherits, OnOrientationChanged));
"Orientation", typeof(Orientation), typeof(ScrollViewerAttach),
new FrameworkPropertyMetadata(ValueBoxes.VerticalBox, FrameworkPropertyMetadataOptions.Inherits,
OnOrientationChanged));
public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.RegisterAttached(
"IsDisabled", typeof(bool), typeof(ScrollViewerAttach),
new PropertyMetadata(ValueBoxes.FalseBox, OnIsDisabledChanged));
public static readonly DependencyProperty IsHoverResizingEnabledProperty = DependencyProperty.RegisterAttached(
"IsHoverResizingEnabled", typeof(bool), typeof(ScrollViewerAttach),
new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits));
public static void SetAutoHide(DependencyObject element, bool value)
{
element.SetValue(AutoHideProperty, ValueBoxes.BooleanBox(value));
}
public static bool GetAutoHide(DependencyObject element)
{
return (bool) element.GetValue(AutoHideProperty);
}
private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ScrollViewer)
switch (d)
{
return;
case ScrollViewer:
return;
case System.Windows.Controls.ScrollViewer scrollViewer
when (Orientation) e.NewValue == Orientation.Horizontal:
scrollViewer.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
break;
case System.Windows.Controls.ScrollViewer scrollViewer:
scrollViewer.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
break;
}
if (d is System.Windows.Controls.ScrollViewer scrollViewer)
{
if ((Orientation) e.NewValue == Orientation.Horizontal)
{
scrollViewer.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
}
else
{
scrollViewer.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
}
}
return;
void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs args)
{
var scrollViewerNative = (System.Windows.Controls.ScrollViewer) sender;
scrollViewerNative.ScrollToHorizontalOffset(Math.Min(Math.Max(0, scrollViewerNative.HorizontalOffset - args.Delta), scrollViewerNative.ScrollableWidth));
scrollViewerNative.ScrollToHorizontalOffset(Math.Min(
Math.Max(0, scrollViewerNative.HorizontalOffset - args.Delta), scrollViewerNative.ScrollableWidth));
args.Handled = true;
}
}
public static void SetOrientation(DependencyObject element, Orientation value)
=> element.SetValue(OrientationProperty, ValueBoxes.OrientationBox(value));
{
element.SetValue(OrientationProperty, ValueBoxes.OrientationBox(value));
}
public static Orientation GetOrientation(DependencyObject element)
=> (Orientation) element.GetValue(OrientationProperty);
public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.RegisterAttached(
"IsDisabled", typeof(bool), typeof(ScrollViewerAttach), new PropertyMetadata(ValueBoxes.FalseBox, OnIsDisabledChanged));
{
return (Orientation) element.GetValue(OrientationProperty);
}
private static void OnIsDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is UIElement element)
if (d is not UIElement element)
{
if ((bool) e.NewValue)
{
element.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
}
else
{
element.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
}
return;
}
if ((bool) e.NewValue)
{
element.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
}
else
{
element.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
}
return;
void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs args)
{
if (args.Handled)
@@ -93,8 +112,22 @@ public class ScrollViewerAttach
}
public static void SetIsDisabled(DependencyObject element, bool value)
=> element.SetValue(IsDisabledProperty, ValueBoxes.BooleanBox(value));
{
element.SetValue(IsDisabledProperty, ValueBoxes.BooleanBox(value));
}
public static bool GetIsDisabled(DependencyObject element)
=> (bool) element.GetValue(IsDisabledProperty);
{
return (bool) element.GetValue(IsDisabledProperty);
}
public static void SetIsHoverResizingEnabled(DependencyObject d, bool value)
{
d.SetValue(IsHoverResizingEnabledProperty, value);
}
public static bool GetIsHoverResizingEnabled(DependencyObject d)
{
return (bool) d.GetValue(IsHoverResizingEnabledProperty);
}
}
@@ -78,6 +78,27 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Width="{TemplateBinding Width}" Background="Transparent">
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" HorizontalAlignment="Right" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="8" Fill="{TemplateBinding Background}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarBaseThumbHorizontal" TargetType="Thumb">
@@ -142,6 +163,27 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Height="{TemplateBinding Height}" Background="Transparent">
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" VerticalAlignment="Bottom" Height="8" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarBaseStyle" TargetType="ScrollBar">
@@ -2010,6 +2010,27 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Width="{TemplateBinding Width}" Background="Transparent">
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" HorizontalAlignment="Right" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="8" Fill="{TemplateBinding Background}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarBaseThumbHorizontal" TargetType="Thumb">
<Setter Property="OverridesDefaultStyle" Value="true" />
@@ -2073,6 +2094,27 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="hc:ScrollViewerAttach.IsHoverResizingEnabled" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Height="{TemplateBinding Height}" Background="Transparent">
<Rectangle x:Name="rectangle" RadiusX="4" RadiusY="4" VerticalAlignment="Bottom" Height="8" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource SecondaryTextBrush}" />
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="rectangle" Value="{DynamicResource PrimaryTextBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarBaseStyle" TargetType="ScrollBar">
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />