Skip to content

Commit 0a792a5

Browse files
committed
feat: add avalonia menu style (step3).
1 parent 61464af commit 0a792a5

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

src/Avalonia/HandyControl_Avalonia/Themes/Styles/ContextMenu.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
Value="1" />
1515
<Setter Property="Background"
1616
Value="{DynamicResource RegionBrush}" />
17+
<Setter Property="BorderBrush"
18+
Value="{DynamicResource BorderBrush}" />
1719
<Setter Property="hc:BorderElement.CornerRadius"
1820
Value="{StaticResource DefaultCornerRadius}" />
1921
<Setter Property="CornerRadius"
@@ -31,7 +33,7 @@
3133
CornerRadius="{TemplateBinding CornerRadius}"
3234
MaxHeight="{TemplateBinding MaxHeight}"
3335
BorderThickness="{TemplateBinding BorderThickness}"
34-
BorderBrush="{DynamicResource BorderBrush}">
36+
BorderBrush="{TemplateBinding BorderBrush}">
3537
<ScrollViewer Theme="{StaticResource ScrollViewerUpDown}"
3638
Margin="{TemplateBinding Padding}">
3739
<ItemsPresenter Name="PART_ItemsPresenter"

src/Avalonia/HandyControl_Avalonia/Themes/Styles/Menu.axaml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
Value="{Binding $self.(hc:MenuAttach.ItemMinHeight)}" />
1212
<Setter Property="Background"
1313
Value="Transparent" />
14+
<Setter Property="BorderBrush"
15+
Value="{DynamicResource BorderBrush}" />
1416
<Setter Property="BorderThickness"
1517
Value="0" />
1618
<Setter Property="Foreground"
@@ -42,12 +44,14 @@
4244
IsVisible="False"
4345
Width="16"
4446
Height="16"
47+
Margin="0,0,10,0"
4548
HorizontalAlignment="Right"
4649
VerticalAlignment="Center" />
4750
<ContentControl Grid.Column="0"
4851
Name="PART_IconPresenter"
4952
Width="16"
5053
Height="16"
54+
Margin="0,0,10,0"
5155
HorizontalAlignment="Right"
5256
VerticalAlignment="Center"
5357
Content="{TemplateBinding Icon}" />
@@ -66,6 +70,8 @@
6670
Grid.Column="3"
6771
VerticalAlignment="Center"
6872
HorizontalAlignment="Left"
73+
Margin="0,0,10,0"
74+
IsVisible="False"
6975
Text="{TemplateBinding InputGesture, Converter={StaticResource PlatformKeyGestureConverter}}" />
7076
<Path Name="rightArrow"
7177
Grid.Column="4"
@@ -108,7 +114,28 @@
108114
Value="{DynamicResource SecondaryRegionBrush}" />
109115
</Style>
110116

111-
<Style Selector="^:empty /template/ Path#rightArrow">
117+
<Style Selector="^:empty">
118+
<Style Selector="^ /template/Path#rightArrow">
119+
<Setter Property="IsVisible"
120+
Value="False" />
121+
</Style>
122+
<Style Selector="^ /template/TextBlock#PART_InputGestureText">
123+
<Setter Property="IsVisible"
124+
Value="True" />
125+
</Style>
126+
</Style>
127+
128+
<Style Selector="^:disabled">
129+
<Setter Property="Opacity"
130+
Value="0.4" />
131+
</Style>
132+
133+
<Style Selector="^:toggle /template/ ContentControl#PART_ToggleIconPresenter, ^:radio /template/ ContentControl#PART_ToggleIconPresenter">
134+
<Setter Property="IsVisible"
135+
Value="True" />
136+
</Style>
137+
138+
<Style Selector="^:toggle /template/ ContentPresenter#PART_IconPresenter, ^:radio /template/ ContentPresenter#PART_IconPresenter">
112139
<Setter Property="IsVisible"
113140
Value="False" />
114141
</Style>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:hc="https://handyorg.github.io/handycontrol">
4+
5+
<ControlTheme x:Key="{x:Type MenuFlyoutPresenter}"
6+
TargetType="MenuFlyoutPresenter">
7+
<Setter Property="hc:MenuAttach.ItemPadding"
8+
Value="{StaticResource DefaultControlPadding}" />
9+
<Setter Property="hc:MenuAttach.ItemMinHeight"
10+
Value="{StaticResource DefaultControlHeight}" />
11+
<Setter Property="hc:MenuAttach.PopupVerticalOffset"
12+
Value="-16" />
13+
<Setter Property="hc:MenuAttach.PopupHorizontalOffset"
14+
Value="1" />
15+
<Setter Property="Background"
16+
Value="{DynamicResource RegionBrush}" />
17+
<Setter Property="BorderBrush"
18+
Value="{DynamicResource BorderBrush}" />
19+
<Setter Property="hc:BorderElement.CornerRadius"
20+
Value="{StaticResource DefaultCornerRadius}" />
21+
<Setter Property="CornerRadius"
22+
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
23+
<Setter Property="Padding"
24+
Value="2,2,2,0" />
25+
<Setter Property="BorderThickness"
26+
Value="1" />
27+
<Setter Property="Template">
28+
<ControlTemplate>
29+
<Border Effect="{StaticResource EffectShadow2}"
30+
Margin="8"
31+
Background="{TemplateBinding Background}"
32+
CornerRadius="{TemplateBinding CornerRadius}"
33+
MaxHeight="{TemplateBinding MaxHeight}"
34+
BorderThickness="{TemplateBinding BorderThickness}"
35+
BorderBrush="{TemplateBinding BorderBrush}">
36+
<ScrollViewer Theme="{StaticResource ScrollViewerUpDown}"
37+
Margin="{TemplateBinding Padding}">
38+
<ItemsPresenter Name="PART_ItemsPresenter"
39+
ItemsPanel="{TemplateBinding ItemsPanel}"
40+
KeyboardNavigation.TabNavigation="Continue" />
41+
</ScrollViewer>
42+
</Border>
43+
</ControlTemplate>
44+
</Setter>
45+
</ControlTheme>
46+
47+
</ResourceDictionary>

src/Avalonia/HandyControl_Avalonia/Themes/Theme.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<MergeResourceInclude Source="/Themes/Basic/Converters.axaml" />
1717

1818
<MergeResourceInclude Source="/Themes/Styles/DataValidationErrors.axaml" />
19+
<MergeResourceInclude Source="/Themes/Styles/MenuFlyoutPresenter.axaml" />
1920
<MergeResourceInclude Source="/Themes/Styles/PopupRoot.axaml" />
2021
<MergeResourceInclude Source="/Themes/Styles/ToolTip.axaml" />
2122
<MergeResourceInclude Source="/Themes/Styles/TextBlock.axaml" />

src/Net_40/HandyControl_Net_40/Themes/Theme.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6353,7 +6353,7 @@
63536353
<ColumnDefinition Width="20" />
63546354
</Grid.ColumnDefinitions>
63556355
<ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16" />
6356-
<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">
6356+
<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">
63576357
<Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" />
63586358
</Border>
63596359
<ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

src/Shared/HandyControl_Shared/Themes/Styles/Base/MenuBaseStyle.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<ColumnDefinition Width="20"/>
2828
</Grid.ColumnDefinitions>
2929
<ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
30-
<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">
30+
<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">
3131
<Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}"/>
3232
</Border>
3333
<ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

src/Shared/HandyControl_Shared/Themes/Theme.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6437,7 +6437,7 @@
64376437
<ColumnDefinition Width="20" />
64386438
</Grid.ColumnDefinitions>
64396439
<ContentPresenter Margin="0,0,10,0" x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Right" Height="16" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16" />
6440-
<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">
6440+
<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">
64416441
<Path UseLayoutRounding="True" Width="12" Height="12" Data="{StaticResource CheckedGeometry}" StrokeThickness="2" Stretch="Uniform" Stroke="{DynamicResource TextIconBrush}" />
64426442
</Border>
64436443
<ContentPresenter Grid.Column="1" x:Name="ContentPresenter" VerticalAlignment="Center" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

0 commit comments

Comments
 (0)