chore: add IsDisabled prop for ScrollViewerAttach.
This commit is contained in:
1 parent
589c07f156
commit
7b68692509
1 file changed
+53
-8
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Tools;
|
||||||
|
|
||||||
namespace HandyControl.Controls;
|
namespace HandyControl.Controls;
|
||||||
|
|
||||||
@@ -30,21 +32,21 @@ public class ScrollViewerAttach
|
|||||||
{
|
{
|
||||||
if ((Orientation) e.NewValue == Orientation.Horizontal)
|
if ((Orientation) e.NewValue == Orientation.Horizontal)
|
||||||
{
|
{
|
||||||
scrollViewer.PreviewMouseWheel += ScrollViewer_PreviewMouseWheel;
|
scrollViewer.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
scrollViewer.PreviewMouseWheel -= ScrollViewer_PreviewMouseWheel;
|
scrollViewer.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs args)
|
||||||
{
|
{
|
||||||
var scrollViewer = (System.Windows.Controls.ScrollViewer) sender;
|
var scrollViewerNative = (System.Windows.Controls.ScrollViewer) sender;
|
||||||
scrollViewer.ScrollToHorizontalOffset(Math.Min(Math.Max(0, scrollViewer.HorizontalOffset - e.Delta), scrollViewer.ScrollableWidth));
|
scrollViewerNative.ScrollToHorizontalOffset(Math.Min(Math.Max(0, scrollViewerNative.HorizontalOffset - args.Delta), scrollViewerNative.ScrollableWidth));
|
||||||
|
|
||||||
e.Handled = true;
|
args.Handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetOrientation(DependencyObject element, Orientation value)
|
public static void SetOrientation(DependencyObject element, Orientation value)
|
||||||
@@ -52,4 +54,47 @@ public class ScrollViewerAttach
|
|||||||
|
|
||||||
public static Orientation GetOrientation(DependencyObject element)
|
public static Orientation GetOrientation(DependencyObject element)
|
||||||
=> (Orientation) element.GetValue(OrientationProperty);
|
=> (Orientation) element.GetValue(OrientationProperty);
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.RegisterAttached(
|
||||||
|
"IsDisabled", typeof(bool), typeof(ScrollViewerAttach), new PropertyMetadata(ValueBoxes.FalseBox, OnIsDisabledChanged));
|
||||||
|
|
||||||
|
private static void OnIsDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (d is UIElement element)
|
||||||
|
{
|
||||||
|
if ((bool)e.NewValue)
|
||||||
|
{
|
||||||
|
element.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
element.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.Handled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
args.Handled = true;
|
||||||
|
|
||||||
|
if (VisualHelper.GetParent<System.Windows.Controls.ScrollViewer>((UIElement) sender) is { } scrollViewer)
|
||||||
|
{
|
||||||
|
scrollViewer.RaiseEvent(new MouseWheelEventArgs(args.MouseDevice, args.Timestamp, args.Delta)
|
||||||
|
{
|
||||||
|
RoutedEvent = UIElement.MouseWheelEvent,
|
||||||
|
Source = sender
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetIsDisabled(DependencyObject element, bool value)
|
||||||
|
=> element.SetValue(IsDisabledProperty, ValueBoxes.BooleanBox(value));
|
||||||
|
|
||||||
|
public static bool GetIsDisabled(DependencyObject element)
|
||||||
|
=> (bool) element.GetValue(IsDisabledProperty);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user