-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add avalonia ScrollViewer demo.
- Loading branch information
Showing
6 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/NativeScrollViewerDemoCtl.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 9 additions & 0 deletions
9
src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/NativeScrollViewerDemoCtl.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace HandyControlDemo.UserControl; | ||
|
||
public partial class NativeScrollViewerDemoCtl : Avalonia.Controls.UserControl | ||
{ | ||
public NativeScrollViewerDemoCtl() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Avalonia/HandyControl_Avalonia/Controls/Attach/ScrollViewerAttach.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters