chore: add avalonia ScrollViewer demo.
This commit is contained in:
1 parent
9122671a4b
commit
64c211f9c0
6 files changed
+211
-6
No files matched your search
@@ -27,9 +27,9 @@ public class BorderElement
|
||||
CircularProperty.Changed.AddClassHandler<AvaloniaObject>(OnCircularChanged);
|
||||
}
|
||||
|
||||
private static void OnCircularChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
|
||||
private static void OnCircularChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is not Border border)
|
||||
if (element is not Border border)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Layout;
|
||||
|
||||
namespace HandyControl.Controls;
|
||||
|
||||
public class ScrollViewerAttach
|
||||
{
|
||||
public static readonly AttachedProperty<Orientation> OrientationProperty =
|
||||
AvaloniaProperty.RegisterAttached<ScrollViewerAttach, AvaloniaObject, Orientation>("Orientation",
|
||||
defaultValue: Orientation.Vertical, inherits: true);
|
||||
|
||||
public static void SetOrientation(AvaloniaObject element, Orientation value) =>
|
||||
element.SetValue(OrientationProperty, value);
|
||||
|
||||
public static Orientation GetOrientation(AvaloniaObject element) => element.GetValue(OrientationProperty);
|
||||
|
||||
static ScrollViewerAttach()
|
||||
{
|
||||
OrientationProperty.Changed.AddClassHandler<AvaloniaObject>(OnOrientationChanged);
|
||||
}
|
||||
|
||||
private static void OnOrientationChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (element is not ScrollViewer scrollViewer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.GetNewValue<Orientation>() == Orientation.Horizontal)
|
||||
{
|
||||
scrollViewer.PointerWheelChanged += ScrollViewerPointerWheelChanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollViewer.PointerWheelChanged -= ScrollViewerPointerWheelChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ScrollViewerPointerWheelChanged(object? sender, PointerWheelEventArgs e)
|
||||
{
|
||||
const int step = 50;
|
||||
|
||||
if (sender is not ScrollViewer scrollViewer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scrollViewer.Offset = new Vector(
|
||||
scrollViewer.Offset.X - e.Delta.Y * step,
|
||||
scrollViewer.Offset.Y
|
||||
);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,9 @@ public class DashedBorder : Decorator
|
||||
BorderDashOffsetProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||
}
|
||||
|
||||
private static void OnClearPenCache(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
|
||||
private static void OnClearPenCache(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var border = (DashedBorder)d;
|
||||
var border = (DashedBorder)element;
|
||||
border._leftPenCache = null;
|
||||
border._rightPenCache = null;
|
||||
border._topPenCache = null;
|
||||
|
||||
@@ -63,9 +63,9 @@ public class UniformSpacingPanel : Panel
|
||||
OrientationProperty.Changed.AddClassHandler<UniformSpacingPanel>(OnOrientationChanged);
|
||||
}
|
||||
|
||||
private static void OnOrientationChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
|
||||
private static void OnOrientationChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var p = (UniformSpacingPanel)d;
|
||||
var p = (UniformSpacingPanel)element;
|
||||
p._orientation = e.GetNewValue<Orientation>();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user