Menu 样式定制完成

This commit is contained in:
polarboy 2024-07-22 15:59:03 +08:00
parent 8cd0567da1
commit d5eef378da
3 changed files with 46 additions and 29 deletions

View File

@ -1,10 +1,22 @@
using AtomUI.Styling;
using Avalonia;
namespace AtomUI.Controls;
using AvaloniaMenu = Avalonia.Controls.Menu;
public class Menu : AvaloniaMenu, IControlCustomStyle
public class Menu : AvaloniaMenu,
ISizeTypeAware
{
#region
public static readonly StyledProperty<SizeType> SizeTypeProperty =
AvaloniaProperty.Register<Button, SizeType>(nameof(SizeType), SizeType.Middle);
public SizeType SizeType
{
get => GetValue(SizeTypeProperty);
set => SetValue(SizeTypeProperty, value);
}
#endregion
}

View File

@ -1,9 +1,11 @@
using AtomUI.Styling;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Styling;
namespace AtomUI.Controls;
@ -33,7 +35,36 @@ public class MenuTheme : ControlTheme
HorizontalAlignment = HorizontalAlignment.Stretch,
Child = itemPresenter,
};
CreateTemplateParentBinding(border, Border.PaddingProperty, Menu.PaddingProperty);
CreateTemplateParentBinding(border, Border.BackgroundProperty, Menu.BackgroundProperty);
CreateTemplateParentBinding(border, Border.BackgroundSizingProperty, Menu.BackgroundSizingProperty);
CreateTemplateParentBinding(border, Border.BorderThicknessProperty, Menu.BorderThicknessProperty);
CreateTemplateParentBinding(border, Border.BorderBrushProperty, Menu.BorderBrushProperty);
CreateTemplateParentBinding(border, Border.CornerRadiusProperty, Menu.CornerRadiusProperty);
return border;
});
}
protected override void BuildStyles()
{
var commonStyle = new Style(selector => selector.Nesting());
commonStyle.Add(Menu.BackgroundProperty, GlobalResourceKey.ColorBgContainer);
commonStyle.Add(Menu.PaddingProperty, new Thickness(0));
commonStyle.Add(Menu.BorderBrushProperty, GlobalResourceKey.ColorBorder);
var largeSizeType = new Style(selector => selector.Nesting().PropertyEquals(Menu.SizeTypeProperty, SizeType.Large));
largeSizeType.Add(Menu.MinHeightProperty, GlobalResourceKey.ControlHeightLG);
largeSizeType.Add(Menu.CornerRadiusProperty, GlobalResourceKey.BorderRadius);
commonStyle.Add(largeSizeType);
var middleSizeType = new Style(selector => selector.Nesting().PropertyEquals(Menu.SizeTypeProperty, SizeType.Middle));
middleSizeType.Add(Menu.MinHeightProperty, GlobalResourceKey.ControlHeight);
middleSizeType.Add(Menu.CornerRadiusProperty, GlobalResourceKey.BorderRadius);
commonStyle.Add(middleSizeType);
var smallSizeType = new Style(selector => selector.Nesting().PropertyEquals(Menu.SizeTypeProperty, SizeType.Small));
smallSizeType.Add(Menu.MinHeightProperty, GlobalResourceKey.ControlHeightSM);
smallSizeType.Add(Menu.CornerRadiusProperty, GlobalResourceKey.BorderRadiusSM);
commonStyle.Add(smallSizeType);
Add(commonStyle);
}
}

View File

@ -1,26 +0,0 @@
using Avalonia;
using Avalonia.Media;
namespace AtomUI.Controls;
public partial class RadioButton
{
// 获取 Token 值属性开始
// private double _dotSizeValueToken;
// private static readonly DirectProperty<RadioButton, double> DotSizeValueTokenProperty =
// AvaloniaProperty.RegisterDirect<RadioButton, double>(
// nameof(_dotSizeValueToken),
// o => o._dotSizeValueToken,
// (o, v) => o._dotSizeValueToken = v);
//
// private double _dotPaddingValueToken;
// private static readonly DirectProperty<RadioButton, double> DotPaddingValueTokenProperty =
// AvaloniaProperty.RegisterDirect<RadioButton, double>(
// nameof(_dotPaddingValueToken),
// o => o._dotPaddingValueToken,
// (o, v) => o._dotPaddingValueToken = v);
//
// 获取 Token 值属性结束
}