From 61464afd3fbb2bb9a45a94485a68fe0dd947f3a8 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Tue, 23 Sep 2025 23:45:25 +0800
Subject: [PATCH] feat: add avalonia menu style (step2).
---
src/Avalonia/Directory.Build.props | 2 +-
.../Controls/Attach/MenuAttach.cs | 14 ++++++--
.../Themes/Styles/ContextMenu.axaml | 16 ++++++---
.../Themes/Styles/Menu.axaml | 34 ++++++++++++-------
.../HandyControl_Net_40/Themes/Theme.xaml | 25 +++++++++-----
.../Controls/Attach/MenuAttach.cs | 19 +++++++++--
.../Styles/Base/ContextMenuBaseStyle.xaml | 6 ++--
.../Themes/Styles/Base/MenuBaseStyle.xaml | 19 ++++++-----
.../Themes/Styles/ContextMenu.xaml | 1 +
.../Themes/Styles/Menu.xaml | 1 +
.../HandyControl_Shared/Themes/Theme.xaml | 25 +++++++++-----
11 files changed, 110 insertions(+), 52 deletions(-)
diff --git a/src/Avalonia/Directory.Build.props b/src/Avalonia/Directory.Build.props
index a131f17e..b7a12c65 100644
--- a/src/Avalonia/Directory.Build.props
+++ b/src/Avalonia/Directory.Build.props
@@ -1,6 +1,6 @@
enable
- 11.3.4
+ 11.3.6
diff --git a/src/Avalonia/HandyControl_Avalonia/Controls/Attach/MenuAttach.cs b/src/Avalonia/HandyControl_Avalonia/Controls/Attach/MenuAttach.cs
index e13e3cc0..018d3d7f 100644
--- a/src/Avalonia/HandyControl_Avalonia/Controls/Attach/MenuAttach.cs
+++ b/src/Avalonia/HandyControl_Avalonia/Controls/Attach/MenuAttach.cs
@@ -5,7 +5,7 @@ namespace HandyControl.Controls;
public class MenuAttach
{
public static readonly AttachedProperty PopupVerticalOffsetProperty =
- AvaloniaProperty.RegisterAttached("PopupVerticalOffset");
+ AvaloniaProperty.RegisterAttached("PopupVerticalOffset", inherits: true);
public static void SetPopupVerticalOffset(AvaloniaObject element, double value) =>
element.SetValue(PopupVerticalOffsetProperty, value);
@@ -14,7 +14,7 @@ public class MenuAttach
element.GetValue(PopupVerticalOffsetProperty);
public static readonly AttachedProperty PopupHorizontalOffsetProperty =
- AvaloniaProperty.RegisterAttached("PopupHorizontalOffset");
+ AvaloniaProperty.RegisterAttached("PopupHorizontalOffset", inherits: true);
public static void SetPopupHorizontalOffset(AvaloniaObject element, double value) =>
element.SetValue(PopupHorizontalOffsetProperty, value);
@@ -23,10 +23,18 @@ public class MenuAttach
element.GetValue(PopupHorizontalOffsetProperty);
public static readonly AttachedProperty ItemPaddingProperty =
- AvaloniaProperty.RegisterAttached("ItemPadding");
+ AvaloniaProperty.RegisterAttached("ItemPadding", inherits: true);
public static void SetItemPadding(AvaloniaObject element, Thickness value) =>
element.SetValue(ItemPaddingProperty, value);
public static Thickness GetItemPadding(AvaloniaObject element) => element.GetValue(ItemPaddingProperty);
+
+ public static readonly AttachedProperty ItemMinHeightProperty =
+ AvaloniaProperty.RegisterAttached("ItemMinHeight", inherits: true);
+
+ public static void SetItemMinHeight(AvaloniaObject element, double value) =>
+ element.SetValue(ItemMinHeightProperty, value);
+
+ public static double GetItemMinHeight(AvaloniaObject element) => element.GetValue(ItemMinHeightProperty);
}
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ContextMenu.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ContextMenu.axaml
index eac8186b..621ede76 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ContextMenu.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ContextMenu.axaml
@@ -6,10 +6,12 @@
TargetType="ContextMenu">
+
+ Value="-16" />
+ Value="1" />
+
@@ -26,7 +30,7 @@
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}"
MaxHeight="{TemplateBinding MaxHeight}"
- BorderThickness="1"
+ BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{DynamicResource BorderBrush}">
@@ -49,10 +53,12 @@
TargetType="ContextMenu">
+
+ Value="-11" />
+ Value="-2" />
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Menu.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Menu.axaml
index cfd2592b..1a27fca6 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Menu.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Menu.axaml
@@ -6,7 +6,9 @@
+ Value="{Binding $self.(hc:MenuAttach.ItemPadding)}" />
+
+ Height="16"
+ HorizontalAlignment="Right"
+ VerticalAlignment="Center" />
@@ -64,10 +65,11 @@
+ Placement="RightEdgeAlignedTop"
+ VerticalOffset="{Binding $self.(hc:MenuAttach.PopupVerticalOffset)}"
+ HorizontalOffset="{Binding $self.(hc:MenuAttach.PopupHorizontalOffset)}">
@@ -112,10 +118,12 @@
TargetType="Menu">
+
+ Value="-16" />
+ Value="1" />
+
+ Value="-11" />
+ Value="-2" />
diff --git a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
index 5e149efa..fdf08db5 100644
--- a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
+++ b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
@@ -6330,6 +6330,8 @@
@@ -7943,16 +7947,18 @@
diff --git a/src/Shared/HandyControl_Shared/Controls/Attach/MenuAttach.cs b/src/Shared/HandyControl_Shared/Controls/Attach/MenuAttach.cs
index eae15cca..5c36b643 100644
--- a/src/Shared/HandyControl_Shared/Controls/Attach/MenuAttach.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Attach/MenuAttach.cs
@@ -6,7 +6,8 @@ namespace HandyControl.Controls;
public class MenuAttach
{
public static readonly DependencyProperty PopupVerticalOffsetProperty = DependencyProperty.RegisterAttached(
- "PopupVerticalOffset", typeof(double), typeof(MenuAttach), new PropertyMetadata(ValueBoxes.Double0Box));
+ "PopupVerticalOffset", typeof(double), typeof(MenuAttach),
+ new FrameworkPropertyMetadata(ValueBoxes.Double0Box, FrameworkPropertyMetadataOptions.Inherits));
public static void SetPopupVerticalOffset(DependencyObject element, double value)
=> element.SetValue(PopupVerticalOffsetProperty, value);
@@ -15,7 +16,8 @@ public class MenuAttach
=> (double) element.GetValue(PopupVerticalOffsetProperty);
public static readonly DependencyProperty PopupHorizontalOffsetProperty = DependencyProperty.RegisterAttached(
- "PopupHorizontalOffset", typeof(double), typeof(MenuAttach), new PropertyMetadata(ValueBoxes.Double0Box));
+ "PopupHorizontalOffset", typeof(double), typeof(MenuAttach),
+ new FrameworkPropertyMetadata(ValueBoxes.Double0Box, FrameworkPropertyMetadataOptions.Inherits));
public static void SetPopupHorizontalOffset(DependencyObject element, double value)
=> element.SetValue(PopupHorizontalOffsetProperty, value);
@@ -24,11 +26,22 @@ public class MenuAttach
=> (double) element.GetValue(PopupHorizontalOffsetProperty);
public static readonly DependencyProperty ItemPaddingProperty = DependencyProperty.RegisterAttached(
- "ItemPadding", typeof(Thickness), typeof(MenuAttach), new PropertyMetadata(default(Thickness)));
+ "ItemPadding", typeof(Thickness), typeof(MenuAttach),
+ new FrameworkPropertyMetadata(default(Thickness), FrameworkPropertyMetadataOptions.Inherits));
public static void SetItemPadding(DependencyObject element, Thickness value)
=> element.SetValue(ItemPaddingProperty, value);
public static Thickness GetItemPadding(DependencyObject element)
=> (Thickness) element.GetValue(ItemPaddingProperty);
+
+ public static readonly DependencyProperty ItemMinHeightProperty = DependencyProperty.RegisterAttached(
+ "ItemMinHeight", typeof(double), typeof(MenuAttach),
+ new FrameworkPropertyMetadata(ValueBoxes.Double0Box, FrameworkPropertyMetadataOptions.Inherits));
+
+ public static void SetItemMinHeight(DependencyObject element, double value)
+ => element.SetValue(ItemMinHeightProperty, value);
+
+ public static double GetItemMinHeight(DependencyObject element)
+ => (double) element.GetValue(ItemMinHeightProperty);
}
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/ContextMenuBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/ContextMenuBaseStyle.xaml
index 3a7aa12c..4cfcf1b2 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/ContextMenuBaseStyle.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/ContextMenuBaseStyle.xaml
@@ -3,16 +3,18 @@
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Menu.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Menu.xaml
index 4466a2cf..a22cd6f6 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Menu.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Menu.xaml
@@ -7,6 +7,7 @@
diff --git a/src/Shared/HandyControl_Shared/Themes/Theme.xaml b/src/Shared/HandyControl_Shared/Themes/Theme.xaml
index 01fbee24..9e93de83 100644
--- a/src/Shared/HandyControl_Shared/Themes/Theme.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Theme.xaml
@@ -6414,6 +6414,8 @@
@@ -8062,16 +8066,18 @@