Skip to content

Commit 2f0b397

Browse files
committed
chore: complete avalonia button style.
1 parent 8a31a48 commit 2f0b397

File tree

17 files changed

+1989
-176
lines changed

17 files changed

+1989
-176
lines changed

src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/ButtonDemoCtl.axaml

Lines changed: 440 additions & 24 deletions
Large diffs are not rendered by default.

src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/RepeatButtonDemoCtl.axaml

Lines changed: 462 additions & 46 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Avalonia;
2+
using Avalonia.Media;
3+
4+
namespace HandyControl.Controls;
5+
6+
public class BackgroundSwitchElement
7+
{
8+
public static readonly AttachedProperty<IBrush> MouseHoverBackgroundProperty =
9+
AvaloniaProperty.RegisterAttached<BackgroundSwitchElement, AvaloniaObject, IBrush>("MouseHoverBackground",
10+
defaultValue: Brushes.Transparent, inherits: true);
11+
12+
public static void SetMouseHoverBackground(AvaloniaObject element, IBrush value) =>
13+
element.SetValue(MouseHoverBackgroundProperty, value);
14+
15+
public static IBrush GetMouseHoverBackground(AvaloniaObject element) =>
16+
element.GetValue(MouseHoverBackgroundProperty);
17+
18+
public static readonly AttachedProperty<IBrush> MouseDownBackgroundProperty =
19+
AvaloniaProperty.RegisterAttached<BackgroundSwitchElement, AvaloniaObject, IBrush>("MouseDownBackground",
20+
defaultValue: Brushes.Transparent, inherits: true);
21+
22+
public static void SetMouseDownBackground(AvaloniaObject element, IBrush value) =>
23+
element.SetValue(MouseDownBackgroundProperty, value);
24+
25+
public static IBrush GetMouseDownBackground(AvaloniaObject element) =>
26+
element.GetValue(MouseDownBackgroundProperty);
27+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Data;
4+
using HandyControl.Tools.Converter;
5+
6+
namespace HandyControl.Controls;
7+
8+
public class BorderElement
9+
{
10+
public static readonly AttachedProperty<CornerRadius> CornerRadiusProperty =
11+
AvaloniaProperty.RegisterAttached<BorderElement, AvaloniaObject, CornerRadius>("CornerRadius", inherits: true);
12+
13+
public static void SetCornerRadius(AvaloniaObject element, CornerRadius value) =>
14+
element.SetValue(CornerRadiusProperty, value);
15+
16+
public static CornerRadius GetCornerRadius(AvaloniaObject element) => element.GetValue(CornerRadiusProperty);
17+
18+
public static readonly AttachedProperty<bool> CircularProperty =
19+
AvaloniaProperty.RegisterAttached<BorderElement, AvaloniaObject, bool>("Circular");
20+
21+
public static void SetCircular(AvaloniaObject element, bool value) => element.SetValue(CircularProperty, value);
22+
23+
public static bool GetCircular(AvaloniaObject element) => element.GetValue(CircularProperty);
24+
25+
static BorderElement()
26+
{
27+
CircularProperty.Changed.AddClassHandler<AvaloniaObject>(OnCircularChanged);
28+
}
29+
30+
private static void OnCircularChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
31+
{
32+
if (d is not Border border)
33+
{
34+
return;
35+
}
36+
37+
if (e.GetNewValue<bool>())
38+
{
39+
var binding = new Binding(Visual.BoundsProperty.Name)
40+
{
41+
Converter = new BorderCircularConverter(),
42+
Source = border,
43+
};
44+
border.Bind(Border.CornerRadiusProperty, binding);
45+
}
46+
else
47+
{
48+
border.ClearValue(Border.CornerRadiusProperty);
49+
}
50+
}
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Avalonia;
2+
using Avalonia.Media;
3+
4+
namespace HandyControl.Controls;
5+
6+
public class IconElement
7+
{
8+
public static readonly AttachedProperty<Geometry> GeometryProperty =
9+
AvaloniaProperty.RegisterAttached<IconElement, AvaloniaObject, Geometry>("Geometry");
10+
11+
public static void SetGeometry(AvaloniaObject element, Geometry value) => element.SetValue(GeometryProperty, value);
12+
13+
public static Geometry GetGeometry(AvaloniaObject element) => element.GetValue(GeometryProperty);
14+
15+
public static readonly AttachedProperty<double> WidthProperty =
16+
AvaloniaProperty.RegisterAttached<IconElement, AvaloniaObject, double>("Width", defaultValue: double.NaN);
17+
18+
public static void SetWidth(AvaloniaObject element, double value) => element.SetValue(WidthProperty, value);
19+
20+
public static double GetWidth(AvaloniaObject element) => element.GetValue(WidthProperty);
21+
22+
public static readonly AttachedProperty<double> HeightProperty =
23+
AvaloniaProperty.RegisterAttached<IconElement, AvaloniaObject, double>("Height", defaultValue: double.NaN);
24+
25+
public static void SetHeight(AvaloniaObject element, double value) => element.SetValue(HeightProperty, value);
26+
public static double GetHeight(AvaloniaObject element) => element.GetValue(HeightProperty);
27+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
xmlns:converter="clr-namespace:HandyControl.Tools.Converter">
44

55
<converter:BorderClipConverter x:Key="BorderClipConverter" />
6+
<converter:BorderCircularConverter x:Key="BorderCircularConverter"/>
7+
<converter:GeometrySpacingConverter x:Key="GeometrySpacingConverter" />
68

79
</ResourceDictionary>

0 commit comments

Comments
 (0)