Skip to content

Commit b4734cd

Browse files
committed
chore: add avalonia Slider demo.
1 parent d81d99d commit b4734cd

File tree

10 files changed

+723
-2
lines changed

10 files changed

+723
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="HandyControlDemo.UserControl.SliderDemo"
4+
xmlns:hc="https://handyorg.github.io/handycontrol"
5+
Background="{DynamicResource RegionBrush}">
6+
<ScrollViewer>
7+
<hc:UniformSpacingPanel Margin="32"
8+
Orientation="Horizontal"
9+
Spacing="32"
10+
ClipToBounds="False"
11+
ChildWrapping="Wrap">
12+
<hc:UniformSpacingPanel Orientation="Vertical"
13+
Spacing="32">
14+
<Slider Width="400"
15+
IsSnapToTickEnabled="True"
16+
TickFrequency="1"
17+
Maximum="10"
18+
Value="8" />
19+
<Slider Width="400"
20+
IsSnapToTickEnabled="True"
21+
TickFrequency="1"
22+
Maximum="10"
23+
Value="3"
24+
IsEnabled="False" />
25+
<Slider Width="400"
26+
IsSnapToTickEnabled="True"
27+
TickFrequency="5"
28+
Maximum="100"
29+
TickPlacement="TopLeft"
30+
Value="10" />
31+
<Slider Width="400"
32+
hc:TipElement.IsVisible="True"
33+
hc:TipElement.Placement="Top"
34+
IsSnapToTickEnabled="True"
35+
Maximum="100"
36+
Value="60"
37+
TickFrequency="10"
38+
TickPlacement="BottomRight" />
39+
<Slider Width="400"
40+
hc:TipElement.IsVisible="True"
41+
hc:TipElement.Placement="Bottom"
42+
hc:TipElement.StringFormat="N2"
43+
TickFrequency="1"
44+
Maximum="10"
45+
Value="5"
46+
TickPlacement="Outside" />
47+
</hc:UniformSpacingPanel>
48+
<hc:UniformSpacingPanel Spacing="32">
49+
<Slider Height="400"
50+
IsSnapToTickEnabled="True"
51+
TickFrequency="1"
52+
Maximum="10"
53+
Value="8"
54+
Orientation="Vertical" />
55+
<Slider Height="400"
56+
IsSnapToTickEnabled="True"
57+
TickFrequency="1"
58+
Maximum="10"
59+
Value="3"
60+
IsEnabled="False"
61+
Orientation="Vertical" />
62+
<Slider Height="400"
63+
IsSnapToTickEnabled="True"
64+
TickFrequency="5"
65+
Maximum="100"
66+
TickPlacement="TopLeft"
67+
Value="10"
68+
Orientation="Vertical" />
69+
<Slider Height="400"
70+
hc:TipElement.IsVisible="True"
71+
hc:TipElement.Placement="Right"
72+
IsSnapToTickEnabled="True"
73+
Maximum="100"
74+
Value="60"
75+
TickFrequency="10"
76+
TickPlacement="BottomRight"
77+
Orientation="Vertical" />
78+
<Slider Height="400"
79+
hc:TipElement.IsVisible="True"
80+
hc:TipElement.Placement="Left"
81+
hc:TipElement.StringFormat="N2"
82+
TickFrequency="1"
83+
Maximum="10"
84+
Value="5"
85+
TickPlacement="Outside"
86+
Orientation="Vertical" />
87+
</hc:UniformSpacingPanel>
88+
</hc:UniformSpacingPanel>
89+
</ScrollViewer>
90+
</UserControl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HandyControlDemo.UserControl;
2+
3+
public partial class SliderDemo : Avalonia.Controls.UserControl
4+
{
5+
public SliderDemo()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Data;
4+
5+
namespace HandyControl.Controls;
6+
7+
public class ContentControlAttach
8+
{
9+
public static readonly AttachedProperty<string> ContentStringFormatProperty =
10+
AvaloniaProperty.RegisterAttached<ContentControlAttach, AvaloniaObject, string>("ContentStringFormat");
11+
12+
public static void SetContentStringFormat(AvaloniaObject element, string value) =>
13+
element.SetValue(ContentStringFormatProperty, value);
14+
15+
public static string GetContentStringFormat(AvaloniaObject element) =>
16+
element.GetValue(ContentStringFormatProperty);
17+
18+
public static readonly AttachedProperty<object?> ContentProperty =
19+
AvaloniaProperty.RegisterAttached<ContentControlAttach, AvaloniaObject, object?>("Content");
20+
21+
public static void SetContent(AvaloniaObject element, object? value) => element.SetValue(ContentProperty, value);
22+
23+
public static object? GetContent(AvaloniaObject element) => element.GetValue(ContentProperty);
24+
25+
static ContentControlAttach()
26+
{
27+
ContentStringFormatProperty.Changed.AddClassHandler<AvaloniaObject>(OnContentChanged);
28+
ContentProperty.Changed.AddClassHandler<AvaloniaObject>(OnContentChanged);
29+
}
30+
31+
private static void OnContentChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e)
32+
{
33+
if (element is not ContentControl contentControl)
34+
{
35+
return;
36+
}
37+
38+
contentControl.ClearValue(ContentControl.ContentProperty);
39+
40+
var binding = new Binding("(ContentControlAttach.Content)")
41+
{
42+
Source = contentControl,
43+
StringFormat = contentControl.GetValue(ContentStringFormatProperty),
44+
TypeResolver = (_, _) => typeof(ContentControlAttach)
45+
};
46+
47+
contentControl.Bind(ContentControl.ContentProperty, binding);
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Avalonia;
2+
using HandyControl.Data;
3+
4+
namespace HandyControl.Controls;
5+
6+
public class TipElement
7+
{
8+
public static readonly AttachedProperty<bool> IsVisibleProperty =
9+
AvaloniaProperty.RegisterAttached<TipElement, AvaloniaObject, bool>("IsVisible");
10+
11+
public static void SetIsVisible(AvaloniaObject element, bool value) => element.SetValue(IsVisibleProperty, value);
12+
13+
public static bool GetIsVisible(AvaloniaObject element) => element.GetValue(IsVisibleProperty);
14+
15+
public static readonly AttachedProperty<PlacementType> PlacementProperty =
16+
AvaloniaProperty.RegisterAttached<TipElement, AvaloniaObject, PlacementType>("Placement");
17+
18+
public static void SetPlacement(AvaloniaObject element, PlacementType value) =>
19+
element.SetValue(PlacementProperty, value);
20+
21+
public static PlacementType GetPlacement(AvaloniaObject element) => element.GetValue(PlacementProperty);
22+
23+
public static readonly AttachedProperty<string> StringFormatProperty =
24+
AvaloniaProperty.RegisterAttached<TipElement, AvaloniaObject, string>("StringFormat", defaultValue: "N1");
25+
26+
public static void SetStringFormat(AvaloniaObject element, string value) =>
27+
element.SetValue(StringFormatProperty, value);
28+
29+
public static string GetStringFormat(AvaloniaObject element) => element.GetValue(StringFormatProperty);
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Layout;
4+
5+
namespace HandyControl.Controls;
6+
7+
public class AxleCanvas : Canvas
8+
{
9+
public static readonly StyledProperty<Orientation> OrientationProperty =
10+
StackPanel.OrientationProperty.AddOwner<AxleCanvas>(new StyledPropertyMetadata<Orientation>(
11+
defaultValue: Orientation.Horizontal));
12+
13+
public Orientation Orientation
14+
{
15+
get => GetValue(OrientationProperty);
16+
set => SetValue(OrientationProperty, value);
17+
}
18+
19+
protected override Size ArrangeOverride(Size finalSize)
20+
{
21+
foreach (Control? internalChild in Children)
22+
{
23+
if (internalChild == null)
24+
{
25+
continue;
26+
}
27+
28+
double x = 0.0;
29+
double y = 0.0;
30+
31+
if (Orientation == Orientation.Horizontal)
32+
{
33+
x = (finalSize.Width - internalChild.DesiredSize.Width) / 2;
34+
35+
double top = GetTop(internalChild);
36+
if (!double.IsNaN(top))
37+
{
38+
y = top;
39+
}
40+
else
41+
{
42+
double bottom = GetBottom(internalChild);
43+
if (!double.IsNaN(bottom))
44+
{
45+
y = finalSize.Height - internalChild.DesiredSize.Height - bottom;
46+
}
47+
}
48+
}
49+
else
50+
{
51+
y = (finalSize.Height - internalChild.DesiredSize.Height) / 2;
52+
53+
double left = GetLeft(internalChild);
54+
if (!double.IsNaN(left))
55+
{
56+
x = left;
57+
}
58+
else
59+
{
60+
double right = GetRight(internalChild);
61+
if (!double.IsNaN(right))
62+
{
63+
x = finalSize.Width - internalChild.DesiredSize.Width - right;
64+
}
65+
}
66+
}
67+
68+
internalChild.Arrange(new Rect(new Point(x, y), internalChild.DesiredSize));
69+
}
70+
71+
return finalSize;
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace HandyControl.Data;
2+
3+
public enum PlacementType
4+
{
5+
LeftTop,
6+
Left,
7+
LeftBottom,
8+
TopLeft,
9+
Top,
10+
TopRight,
11+
RightTop,
12+
Right,
13+
RightBottom,
14+
BottomLeft,
15+
Bottom,
16+
BottomRight,
17+
}

src/Avalonia/HandyControl_Avalonia/Themes/Basic/Effects.axaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ResourceDictionary xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
33

4-
<Color x:Key="EffectShadowColor">#88000000</Color>
4+
<Color x:Key="EffectShadowColor">Black</Color>
55

66
<DropShadowEffect x:Key="EffectShadow1"
77
BlurRadius="5"

0 commit comments

Comments
 (0)