feat: add avalonia menu style (step3).

This commit is contained in:
NaBian committed 2025-09-25 22:15:18 +08:00
1 parent 61464afd3f
commit 0a792a5964
7 files changed
+82 -5

No files matched your search

@@ -14,6 +14,8 @@
Value="1" /> Value="1" />
<Setter Property="Background" <Setter Property="Background"
Value="{DynamicResource RegionBrush}" /> Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="hc:BorderElement.CornerRadius" <Setter Property="hc:BorderElement.CornerRadius"
Value="{StaticResource DefaultCornerRadius}" /> Value="{StaticResource DefaultCornerRadius}" />
<Setter Property="CornerRadius" <Setter Property="CornerRadius"
@@ -31,7 +33,7 @@
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
MaxHeight="{TemplateBinding MaxHeight}" MaxHeight="{TemplateBinding MaxHeight}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{DynamicResource BorderBrush}"> BorderBrush="{TemplateBinding BorderBrush}">
<ScrollViewer Theme="{StaticResource ScrollViewerUpDown}" <ScrollViewer Theme="{StaticResource ScrollViewerUpDown}"
Margin="{TemplateBinding Padding}"> Margin="{TemplateBinding Padding}">
<ItemsPresenter Name="PART_ItemsPresenter" <ItemsPresenter Name="PART_ItemsPresenter"
@@ -11,6 +11,8 @@
Value="{Binding $self.(hc:MenuAttach.ItemMinHeight)}" /> Value="{Binding $self.(hc:MenuAttach.ItemMinHeight)}" />
<Setter Property="Background" <Setter Property="Background"
Value="Transparent" /> Value="Transparent" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="BorderThickness" <Setter Property="BorderThickness"
Value="0" /> Value="0" />
<Setter Property="Foreground" <Setter Property="Foreground"
@@ -42,12 +44,14 @@
IsVisible="False" IsVisible="False"
Width="16" Width="16"
Height="16" Height="16"
Margin="0,0,10,0"
HorizontalAlignment="Right" HorizontalAlignment="Right"
VerticalAlignment="Center" /> VerticalAlignment="Center" />
<ContentControl Grid.Column="0" <ContentControl Grid.Column="0"
Name="PART_IconPresenter" Name="PART_IconPresenter"
Width="16" Width="16"
Height="16" Height="16"
Margin="0,0,10,0"
HorizontalAlignment="Right" HorizontalAlignment="Right"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="{TemplateBinding Icon}" /> Content="{TemplateBinding Icon}" />
@@ -66,6 +70,8 @@
Grid.Column="3" Grid.Column="3"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Margin="0,0,10,0"
IsVisible="False"
Text="{TemplateBinding InputGesture, Converter={StaticResource PlatformKeyGestureConverter}}" /> Text="{TemplateBinding InputGesture, Converter={StaticResource PlatformKeyGestureConverter}}" />
<Path Name="rightArrow" <Path Name="rightArrow"
Grid.Column="4" Grid.Column="4"
@@ -108,7 +114,28 @@
Value="{DynamicResource SecondaryRegionBrush}" /> Value="{DynamicResource SecondaryRegionBrush}" />
</Style> </Style>
<Style Selector="^:empty /template/ Path#rightArrow"> <Style Selector="^:empty">
<Style Selector="^ /template/Path#rightArrow">
<Setter Property="IsVisible"
Value="False" />
</Style>
<Style Selector="^ /template/TextBlock#PART_InputGestureText">
<Setter Property="IsVisible"
Value="True" />
</Style>
</Style>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
<Style Selector="^:toggle /template/ ContentControl#PART_ToggleIconPresenter, ^:radio /template/ ContentControl#PART_ToggleIconPresenter">
<Setter Property="IsVisible"
Value="True" />
</Style>
<Style Selector="^:toggle /template/ ContentPresenter#PART_IconPresenter, ^:radio /template/ ContentPresenter#PART_IconPresenter">
<Setter Property="IsVisible" <Setter Property="IsVisible"
Value="False" /> Value="False" />
</Style> </Style>
@@ -0,0 +1,47 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol">
<ControlTheme x:Key="{x:Type MenuFlyoutPresenter}"
TargetType="MenuFlyoutPresenter">
<Setter Property="hc:MenuAttach.ItemPadding"
Value="{StaticResource DefaultControlPadding}" />
<Setter Property="hc:MenuAttach.ItemMinHeight"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="hc:MenuAttach.PopupVerticalOffset"
Value="-16" />
<Setter Property="hc:MenuAttach.PopupHorizontalOffset"
Value="1" />
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="hc:BorderElement.CornerRadius"
Value="{StaticResource DefaultCornerRadius}" />
<Setter Property="CornerRadius"
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
<Setter Property="Padding"
Value="2,2,2,0" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Template">
<ControlTemplate>
<Border Effect="{StaticResource EffectShadow2}"
Margin="8"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}"
MaxHeight="{TemplateBinding MaxHeight}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<ScrollViewer Theme="{StaticResource ScrollViewerUpDown}"
Margin="{TemplateBinding Padding}">
<ItemsPresenter Name="PART_ItemsPresenter"
ItemsPanel="{TemplateBinding ItemsPanel}"
KeyboardNavigation.TabNavigation="Continue" />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
@@ -16,6 +16,7 @@
<MergeResourceInclude Source="/Themes/Basic/Converters.axaml" /> <MergeResourceInclude Source="/Themes/Basic/Converters.axaml" />
<MergeResourceInclude Source="/Themes/Styles/DataValidationErrors.axaml" /> <MergeResourceInclude Source="/Themes/Styles/DataValidationErrors.axaml" />
<MergeResourceInclude Source="/Themes/Styles/MenuFlyoutPresenter.axaml" />
<MergeResourceInclude Source="/Themes/Styles/PopupRoot.axaml" /> <MergeResourceInclude Source="/Themes/Styles/PopupRoot.axaml" />
<MergeResourceInclude Source="/Themes/Styles/ToolTip.axaml" /> <MergeResourceInclude Source="/Themes/Styles/ToolTip.axaml" />
<MergeResourceInclude Source="/Themes/Styles/TextBlock.axaml" /> <MergeResourceInclude Source="/Themes/Styles/TextBlock.axaml" />
@@ -6353,7 +6353,7 @@
<ColumnDefinition Width="20" /> <ColumnDefinition Width="20" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16" /> <ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16" />
<Border Margin="0,0,10,0" IsHitTestVisible="False" Grid.Column="0" x:Name="GlyphPanel" CornerRadius="2" Background="Red" ClipToBounds="False" HorizontalAlignment="Right" Height="16" Visibility="Hidden" VerticalAlignment="Center" Width="16"> <Border Margin="0,0,10,0" IsHitTestVisible="False" Grid.Column="0" x:Name="GlyphPanel" CornerRadius="2" Background="{DynamicResource PrimaryBrush}" ClipToBounds="False" HorizontalAlignment="Right" Height="16" Visibility="Hidden" VerticalAlignment="Center" Width="16">
<Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" /> <Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" />
</Border> </Border>
<ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> <ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
@@ -27,7 +27,7 @@
<ColumnDefinition Width="20"/> <ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> <ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
<Border Margin="0,0,10,0" IsHitTestVisible="False" Grid.Column="0" x:Name="GlyphPanel" CornerRadius="2" Background="Red" ClipToBounds="False" HorizontalAlignment="Right" Height="16" Visibility="Hidden" VerticalAlignment="Center" Width="16"> <Border Margin="0,0,10,0" IsHitTestVisible="False" Grid.Column="0" x:Name="GlyphPanel" CornerRadius="2" Background="{DynamicResource PrimaryBrush}" ClipToBounds="False" HorizontalAlignment="Right" Height="16" Visibility="Hidden" VerticalAlignment="Center" Width="16">
<Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}"/> <Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}"/>
</Border> </Border>
<ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
@@ -6437,7 +6437,7 @@
<ColumnDefinition Width="20" /> <ColumnDefinition Width="20" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16" /> <ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16" />
<Border Margin="0,0,10,0" IsHitTestVisible="False" Grid.Column="0" x:Name="GlyphPanel" CornerRadius="2" Background="Red" ClipToBounds="False" HorizontalAlignment="Right" Height="16" Visibility="Hidden" VerticalAlignment="Center" Width="16"> <Border Margin="0,0,10,0" IsHitTestVisible="False" Grid.Column="0" x:Name="GlyphPanel" CornerRadius="2" Background="{DynamicResource PrimaryBrush}" ClipToBounds="False" HorizontalAlignment="Right" Height="16" Visibility="Hidden" VerticalAlignment="Center" Width="16">
<Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" /> <Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" />
</Border> </Border>
<ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> <ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />