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
+139
@@ -0,0 +1,139 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="HandyControlDemo.UserControl.NativeScrollViewerDemoCtl"
|
||||||
|
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||||
|
Background="{DynamicResource RegionBrush}"
|
||||||
|
MaxWidth="550"
|
||||||
|
Height="600">
|
||||||
|
<Grid Margin="32"
|
||||||
|
RowDefinitions="Auto, *">
|
||||||
|
<Border BorderThickness="1"
|
||||||
|
BorderBrush="{DynamicResource BorderBrush}">
|
||||||
|
<ScrollViewer hc:ScrollViewerAttach.Orientation="Horizontal"
|
||||||
|
HorizontalScrollBarVisibility="Auto"
|
||||||
|
VerticalScrollBarVisibility="Hidden">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
</Border>
|
||||||
|
<Border Grid.Row="1"
|
||||||
|
BorderThickness="1"
|
||||||
|
BorderBrush="{DynamicResource BorderBrush}"
|
||||||
|
Margin="0,16,0,0">
|
||||||
|
<ScrollViewer>
|
||||||
|
<WrapPanel Orientation="Horizontal">
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
<Border Theme="{StaticResource BorderRegion}"
|
||||||
|
Width="200"
|
||||||
|
Height="200"
|
||||||
|
Margin="10,10,32,10">
|
||||||
|
<Border Background="{DynamicResource PrimaryBrush}">
|
||||||
|
<TextBlock Text="Content"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="White" />
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
</WrapPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
namespace HandyControlDemo.UserControl;
|
||||||
|
|
||||||
|
public partial class NativeScrollViewerDemoCtl : Avalonia.Controls.UserControl
|
||||||
|
{
|
||||||
|
public NativeScrollViewerDemoCtl()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,9 +27,9 @@ public class BorderElement
|
|||||||
CircularProperty.Changed.AddClassHandler<AvaloniaObject>(OnCircularChanged);
|
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;
|
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);
|
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._leftPenCache = null;
|
||||||
border._rightPenCache = null;
|
border._rightPenCache = null;
|
||||||
border._topPenCache = null;
|
border._topPenCache = null;
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ public class UniformSpacingPanel : Panel
|
|||||||
OrientationProperty.Changed.AddClassHandler<UniformSpacingPanel>(OnOrientationChanged);
|
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>();
|
p._orientation = e.GetNewValue<Orientation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user