Skip to content

Commit 64c211f

Browse files
committed
chore: add avalonia ScrollViewer demo.
1 parent 9122671 commit 64c211f

File tree

6 files changed

+211
-6
lines changed

6 files changed

+211
-6
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="HandyControlDemo.UserControl.NativeScrollViewerDemoCtl"
4+
xmlns:hc="https://handyorg.github.io/handycontrol"
5+
Background="{DynamicResource RegionBrush}"
6+
MaxWidth="550"
7+
Height="600">
8+
<Grid Margin="32"
9+
RowDefinitions="Auto, *">
10+
<Border BorderThickness="1"
11+
BorderBrush="{DynamicResource BorderBrush}">
12+
<ScrollViewer hc:ScrollViewerAttach.Orientation="Horizontal"
13+
HorizontalScrollBarVisibility="Auto"
14+
VerticalScrollBarVisibility="Hidden">
15+
<StackPanel Orientation="Horizontal">
16+
<Border Theme="{StaticResource BorderRegion}"
17+
Width="200"
18+
Height="200"
19+
Margin="10,10,32,10">
20+
<Border Background="{DynamicResource PrimaryBrush}">
21+
<TextBlock Text="Content"
22+
VerticalAlignment="Center"
23+
HorizontalAlignment="Center"
24+
Foreground="White" />
25+
</Border>
26+
</Border>
27+
<Border Theme="{StaticResource BorderRegion}"
28+
Width="200"
29+
Height="200"
30+
Margin="10,10,32,10">
31+
<Border Background="{DynamicResource PrimaryBrush}">
32+
<TextBlock Text="Content"
33+
VerticalAlignment="Center"
34+
HorizontalAlignment="Center"
35+
Foreground="White" />
36+
</Border>
37+
</Border>
38+
<Border Theme="{StaticResource BorderRegion}"
39+
Width="200"
40+
Height="200"
41+
Margin="10,10,32,10">
42+
<Border Background="{DynamicResource PrimaryBrush}">
43+
<TextBlock Text="Content"
44+
VerticalAlignment="Center"
45+
HorizontalAlignment="Center"
46+
Foreground="White" />
47+
</Border>
48+
</Border>
49+
<Border Theme="{StaticResource BorderRegion}"
50+
Width="200"
51+
Height="200"
52+
Margin="10,10,32,10">
53+
<Border Background="{DynamicResource PrimaryBrush}">
54+
<TextBlock Text="Content"
55+
VerticalAlignment="Center"
56+
HorizontalAlignment="Center"
57+
Foreground="White" />
58+
</Border>
59+
</Border>
60+
<Border Theme="{StaticResource BorderRegion}"
61+
Width="200"
62+
Height="200"
63+
Margin="10,10,32,10">
64+
<Border Background="{DynamicResource PrimaryBrush}">
65+
<TextBlock Text="Content"
66+
VerticalAlignment="Center"
67+
HorizontalAlignment="Center"
68+
Foreground="White" />
69+
</Border>
70+
</Border>
71+
</StackPanel>
72+
</ScrollViewer>
73+
</Border>
74+
<Border Grid.Row="1"
75+
BorderThickness="1"
76+
BorderBrush="{DynamicResource BorderBrush}"
77+
Margin="0,16,0,0">
78+
<ScrollViewer>
79+
<WrapPanel Orientation="Horizontal">
80+
<Border Theme="{StaticResource BorderRegion}"
81+
Width="200"
82+
Height="200"
83+
Margin="10,10,32,10">
84+
<Border Background="{DynamicResource PrimaryBrush}">
85+
<TextBlock Text="Content"
86+
VerticalAlignment="Center"
87+
HorizontalAlignment="Center"
88+
Foreground="White" />
89+
</Border>
90+
</Border>
91+
<Border Theme="{StaticResource BorderRegion}"
92+
Width="200"
93+
Height="200"
94+
Margin="10,10,32,10">
95+
<Border Background="{DynamicResource PrimaryBrush}">
96+
<TextBlock Text="Content"
97+
VerticalAlignment="Center"
98+
HorizontalAlignment="Center"
99+
Foreground="White" />
100+
</Border>
101+
</Border>
102+
<Border Theme="{StaticResource BorderRegion}"
103+
Width="200"
104+
Height="200"
105+
Margin="10,10,32,10">
106+
<Border Background="{DynamicResource PrimaryBrush}">
107+
<TextBlock Text="Content"
108+
VerticalAlignment="Center"
109+
HorizontalAlignment="Center"
110+
Foreground="White" />
111+
</Border>
112+
</Border>
113+
<Border Theme="{StaticResource BorderRegion}"
114+
Width="200"
115+
Height="200"
116+
Margin="10,10,32,10">
117+
<Border Background="{DynamicResource PrimaryBrush}">
118+
<TextBlock Text="Content"
119+
VerticalAlignment="Center"
120+
HorizontalAlignment="Center"
121+
Foreground="White" />
122+
</Border>
123+
</Border>
124+
<Border Theme="{StaticResource BorderRegion}"
125+
Width="200"
126+
Height="200"
127+
Margin="10,10,32,10">
128+
<Border Background="{DynamicResource PrimaryBrush}">
129+
<TextBlock Text="Content"
130+
VerticalAlignment="Center"
131+
HorizontalAlignment="Center"
132+
Foreground="White" />
133+
</Border>
134+
</Border>
135+
</WrapPanel>
136+
</ScrollViewer>
137+
</Border>
138+
</Grid>
139+
</UserControl>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HandyControlDemo.UserControl;
2+
3+
public partial class NativeScrollViewerDemoCtl : Avalonia.Controls.UserControl
4+
{
5+
public NativeScrollViewerDemoCtl()
6+
{
7+
InitializeComponent();
8+
}
9+
}

src/Avalonia/HandyControl_Avalonia/Controls/Attach/BorderElement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ static BorderElement()
2727
CircularProperty.Changed.AddClassHandler<AvaloniaObject>(OnCircularChanged);
2828
}
2929

30-
private static void OnCircularChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
30+
private static void OnCircularChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
3131
{
32-
if (d is not Border border)
32+
if (element is not Border border)
3333
{
3434
return;
3535
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Input;
4+
using Avalonia.Layout;
5+
6+
namespace HandyControl.Controls;
7+
8+
public class ScrollViewerAttach
9+
{
10+
public static readonly AttachedProperty<Orientation> OrientationProperty =
11+
AvaloniaProperty.RegisterAttached<ScrollViewerAttach, AvaloniaObject, Orientation>("Orientation",
12+
defaultValue: Orientation.Vertical, inherits: true);
13+
14+
public static void SetOrientation(AvaloniaObject element, Orientation value) =>
15+
element.SetValue(OrientationProperty, value);
16+
17+
public static Orientation GetOrientation(AvaloniaObject element) => element.GetValue(OrientationProperty);
18+
19+
static ScrollViewerAttach()
20+
{
21+
OrientationProperty.Changed.AddClassHandler<AvaloniaObject>(OnOrientationChanged);
22+
}
23+
24+
private static void OnOrientationChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
25+
{
26+
if (element is not ScrollViewer scrollViewer)
27+
{
28+
return;
29+
}
30+
31+
if (e.GetNewValue<Orientation>() == Orientation.Horizontal)
32+
{
33+
scrollViewer.PointerWheelChanged += ScrollViewerPointerWheelChanged;
34+
}
35+
else
36+
{
37+
scrollViewer.PointerWheelChanged -= ScrollViewerPointerWheelChanged;
38+
}
39+
}
40+
41+
private static void ScrollViewerPointerWheelChanged(object? sender, PointerWheelEventArgs e)
42+
{
43+
const int step = 50;
44+
45+
if (sender is not ScrollViewer scrollViewer)
46+
{
47+
return;
48+
}
49+
50+
scrollViewer.Offset = new Vector(
51+
scrollViewer.Offset.X - e.Delta.Y * step,
52+
scrollViewer.Offset.Y
53+
);
54+
55+
e.Handled = true;
56+
}
57+
}

src/Avalonia/HandyControl_Avalonia/Controls/Other/DashedBorder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ static DashedBorder()
7171
BorderDashOffsetProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
7272
}
7373

74-
private static void OnClearPenCache(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
74+
private static void OnClearPenCache(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
7575
{
76-
var border = (DashedBorder)d;
76+
var border = (DashedBorder)element;
7777
border._leftPenCache = null;
7878
border._rightPenCache = null;
7979
border._topPenCache = null;

src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ static UniformSpacingPanel()
6363
OrientationProperty.Changed.AddClassHandler<UniformSpacingPanel>(OnOrientationChanged);
6464
}
6565

66-
private static void OnOrientationChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
66+
private static void OnOrientationChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
6767
{
68-
var p = (UniformSpacingPanel)d;
68+
var p = (UniformSpacingPanel)element;
6969
p._orientation = e.GetNewValue<Orientation>();
7070
}
7171

0 commit comments

Comments
 (0)