Skip to content

Commit 7b81d6d

Browse files
authored
Add Menu & ContextMenu (#41)
1 parent 3b296e3 commit 7b81d6d

File tree

9 files changed

+210
-256
lines changed

9 files changed

+210
-256
lines changed

samples/SampleApp/DemoPages/ContextMenuDemo.axaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
<Border Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20">
99
<Border.ContextMenu>
1010
<ContextMenu>
11-
<MenuItem Header="Copy" />
12-
<MenuItem Header="Paste" />
11+
<MenuItem Header="Standard _Menu Item" />
12+
<MenuItem Header="Disabled" IsEnabled="False" />
13+
<Separator />
14+
<MenuItem Header="Menu with _Submenu">
15+
<MenuItem Header="Submenu _1" />
16+
<MenuItem Header="Submenu _2" />
17+
</MenuItem>
1318
</ContextMenu>
1419
</Border.ContextMenu>
1520
<TextBlock Margin="10">Right-click anywhere in this space</TextBlock>
1621
</Border>
1722

23+
1824
</UserControl>

samples/SampleApp/DemoPages/MenuDemo.axaml

+79-195
Original file line numberDiff line numberDiff line change
@@ -4,207 +4,91 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
66
x:Class="SampleApp.DemoPages.MenuDemo">
7-
<Panel>
8-
<Panel.Styles>
9-
<Style Selector="MenuItem Image">
10-
<Setter Property="Width" Value="15" />
11-
<Setter Property="Height" Value="15" />
12-
</Style>
137

14-
<Style Selector="MenuItem > StackPanel">
15-
<Setter Property="Spacing" Value="10" />
16-
<Setter Property="Orientation" Value="Horizontal" />
17-
</Style>
18-
</Panel.Styles>
19-
20-
21-
<DockPanel>
22-
<Menu DockPanel.Dock="Top">
23-
<MenuItem IsEnabled="True">
24-
<MenuItem.Header>
25-
<StackPanel>
26-
<Image Source="{StaticResource FolderIcon}" />
27-
<TextBlock Text="File" />
28-
</StackPanel>
29-
</MenuItem.Header>
30-
<MenuItem Header="Menu Item">
31-
<MenuItem.Icon>
32-
<Image Source="{StaticResource FolderIcon}" />
33-
</MenuItem.Icon>
34-
</MenuItem>
35-
<MenuItem Header="Menu Item">
36-
<MenuItem.Icon>
37-
<Image Source="{StaticResource FolderIcon}" />
38-
</MenuItem.Icon>
39-
</MenuItem>
40-
<MenuItem Header="Big Icon">
41-
<MenuItem.Icon>
42-
<Image Source="{StaticResource FolderIcon}" />
43-
</MenuItem.Icon>
44-
</MenuItem>
45-
<MenuItem Header="Copy">
46-
<MenuItem.Icon>
47-
<PathIcon Data="{StaticResource PasswordRevealPath}" />
48-
</MenuItem.Icon>
49-
</MenuItem>
50-
</MenuItem>
51-
52-
<MenuItem IsEnabled="True" Header="Test">
8+
<DockPanel>
9+
<Menu DockPanel.Dock="Top" VerticalAlignment="Top">
10+
<MenuItem Header="File">
11+
<MenuItem Header="Open session" InputGesture="&#x2318;+O" />
12+
<MenuItem Header="Open with parameters">
13+
<MenuItem Header="Open (embedded/tabbed)" />
14+
<MenuItem Header="Open embedded SFTP connection" />
15+
<MenuItem Header="Open embedded SCP connection" InputGesture="&#x2318;+S" IsEnabled="False" />
16+
<MenuItem Header="-" />
17+
<MenuItem Header="Open (select credentials)..." />
18+
</MenuItem>
19+
<MenuItem Header="View password" />
20+
<MenuItem Header="Copy name" />
21+
<MenuItem Header="Copy password" />
22+
<MenuItem Header="-" />
23+
<MenuItem Header="Focus session" />
24+
<MenuItem Header="Edit" IsEnabled="False">
25+
<MenuItem Header="Dummy1" />
26+
<MenuItem Header="Dummy2" />
27+
</MenuItem>
28+
<MenuItem Header="Toggle Options">
29+
<MenuItem Header="Option 1" ToggleType="CheckBox" />
30+
<MenuItem Header="Option 2" ToggleType="CheckBox" IsChecked="True" />
31+
</MenuItem>
32+
</MenuItem>
33+
<MenuItem Header="Edit">
34+
<MenuItem Header="Menu Item">
5335
<MenuItem.Icon>
54-
<PathIcon Data="{StaticResource PasswordRevealPath}"
55-
Height="9" Width="12" />
36+
<Image Source="{StaticResource FolderIcon}" />
5637
</MenuItem.Icon>
5738
</MenuItem>
58-
59-
<MenuItem IsEnabled="False">
60-
<MenuItem.Header>
61-
<StackPanel>
62-
<Image Source="{StaticResource FolderIcon}" />
63-
<TextBlock Text="Menu Item" />
64-
</StackPanel>
65-
</MenuItem.Header>
66-
</MenuItem>
67-
68-
<MenuItem IsEnabled="True">
69-
<MenuItem.Header>
70-
<StackPanel>
71-
<Image Source="{StaticResource FolderIcon}" />
72-
<TextBlock Text="Menu Item" />
73-
</StackPanel>
74-
</MenuItem.Header>
75-
</MenuItem>
76-
77-
<MenuItem IsEnabled="True">
78-
<MenuItem.Header>
79-
<StackPanel>
80-
<Image Source="{StaticResource FolderIcon}" />
81-
<TextBlock Text="Menu Item" />
82-
</StackPanel>
83-
</MenuItem.Header>
84-
</MenuItem>
85-
86-
<MenuItem IsEnabled="True">
87-
<MenuItem.Header>
88-
<StackPanel>
89-
<Image Source="{StaticResource FolderIcon}" />
90-
<TextBlock Text="Menu Item" />
91-
</StackPanel>
92-
</MenuItem.Header>
93-
</MenuItem>
94-
95-
<MenuItem IsEnabled="True">
96-
<MenuItem.Header>
97-
<StackPanel>
98-
<Image Source="{StaticResource FolderIcon}" />
99-
<TextBlock Text="Menu Item" />
100-
</StackPanel>
101-
</MenuItem.Header>
102-
</MenuItem>
103-
104-
<MenuItem>
105-
<MenuItem.Header>
106-
<StackPanel>
107-
<Image Source="{StaticResource FolderIcon}" />
108-
<TextBlock Text="Menu Item" />
109-
</StackPanel>
110-
</MenuItem.Header>
111-
</MenuItem>
112-
</Menu>
113-
114-
<Menu DockPanel.Dock="Bottom">
115-
<MenuItem IsEnabled="True">
116-
<MenuItem.Header>
117-
<StackPanel>
118-
<Image Source="{StaticResource FolderIcon}" />
119-
<TextBlock Text="Menu Item" />
120-
</StackPanel>
121-
</MenuItem.Header>
122-
<MenuItem Header="Menu Item">
123-
<MenuItem.Icon>
124-
<Image Source="{StaticResource FolderIcon}" />
125-
</MenuItem.Icon>
126-
</MenuItem>
127-
<MenuItem Header="Menu Item">
128-
<MenuItem.Icon>
129-
<Image Source="{StaticResource FolderIcon}" />
130-
</MenuItem.Icon>
131-
</MenuItem>
132-
<MenuItem Header="Big Icon">
133-
<MenuItem.Icon>
134-
<Image Source="{StaticResource FolderIcon}" />
135-
</MenuItem.Icon>
136-
</MenuItem>
137-
<MenuItem Header="Copy">
138-
<MenuItem.Icon>
139-
<PathIcon Data="{StaticResource PasswordRevealPath}" />
140-
</MenuItem.Icon>
141-
</MenuItem>
142-
</MenuItem>
143-
144-
<MenuItem IsEnabled="True" Header="Test">
39+
<MenuItem Header="Menu Item" />
40+
<MenuItem Header="Menu Item" />
41+
<MenuItem Header="-" />
42+
<MenuItem Header="Menu Item" />
43+
</MenuItem>
44+
</Menu>
45+
46+
<Menu DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
47+
<MenuItem Header="File">
48+
<MenuItem Header="Open session" InputGesture="&#x2318;+O" />
49+
<MenuItem Header="Open with parameters">
50+
<MenuItem Header="Open (embedded/tabbed)" />
51+
<MenuItem Header="Open embedded SFTP connection" />
52+
<MenuItem Header="Open embedded SCP connection" InputGesture="&#x2318;+S" IsEnabled="False" />
53+
<MenuItem Header="-" />
54+
<MenuItem Header="Open (select credentials)..." />
55+
</MenuItem>
56+
<MenuItem Header="View password" />
57+
<MenuItem Header="Copy name" />
58+
<MenuItem Header="Copy password" />
59+
<MenuItem Header="-" />
60+
<MenuItem Header="Focus session" />
61+
<MenuItem Header="Edit" IsEnabled="False">
62+
<MenuItem Header="Dummy1" />
63+
<MenuItem Header="Dummy2" />
64+
</MenuItem>
65+
<MenuItem Header="Toggle Options">
66+
<MenuItem Header="Option 1" ToggleType="CheckBox" />
67+
<MenuItem Header="Option 2" ToggleType="CheckBox" IsChecked="True" />
68+
</MenuItem>
69+
</MenuItem>
70+
<MenuItem Header="Edit">
71+
<MenuItem Header="Menu Item">
14572
<MenuItem.Icon>
146-
<PathIcon Data="{StaticResource PasswordRevealPath}"
147-
Height="9" Width="12" />
73+
<Image Source="{StaticResource FolderIcon}" />
14874
</MenuItem.Icon>
14975
</MenuItem>
150-
151-
<MenuItem IsEnabled="False">
152-
<MenuItem.Header>
153-
<StackPanel>
154-
<Image Source="{StaticResource FolderIcon}" />
155-
<TextBlock Text="Menu Item" />
156-
</StackPanel>
157-
</MenuItem.Header>
158-
</MenuItem>
159-
160-
<MenuItem IsEnabled="True">
161-
<MenuItem.Header>
162-
<StackPanel>
163-
<Image Source="{StaticResource FolderIcon}" />
164-
<TextBlock Text="Menu Item" />
165-
</StackPanel>
166-
</MenuItem.Header>
167-
</MenuItem>
168-
169-
<MenuItem IsEnabled="True">
170-
<MenuItem.Header>
171-
<StackPanel>
172-
<Image Source="{StaticResource FolderIcon}" />
173-
<TextBlock Text="Menu Item" />
174-
</StackPanel>
175-
</MenuItem.Header>
176-
</MenuItem>
177-
178-
<MenuItem IsEnabled="True">
179-
<MenuItem.Header>
180-
<StackPanel>
181-
<Image Source="{StaticResource FolderIcon}" />
182-
<TextBlock Text="Menu Item" />
183-
</StackPanel>
184-
</MenuItem.Header>
185-
</MenuItem>
186-
187-
<MenuItem IsEnabled="True">
188-
<MenuItem.Header>
189-
<StackPanel>
190-
<Image Source="{StaticResource FolderIcon}" />
191-
<TextBlock Text="Menu Item" />
192-
</StackPanel>
193-
</MenuItem.Header>
194-
</MenuItem>
195-
196-
<MenuItem>
197-
<MenuItem.Header>
198-
<StackPanel>
199-
<Image Source="{StaticResource FolderIcon}" />
200-
<TextBlock Text="Menu Item" />
201-
</StackPanel>
202-
</MenuItem.Header>
203-
</MenuItem>
204-
</Menu>
205-
206-
<Border Background="Silver" />
207-
</DockPanel>
208-
</Panel>
76+
<MenuItem Header="Menu Item" />
77+
<MenuItem Header="Menu Item" />
78+
<MenuItem Header="-" />
79+
<MenuItem Header="Menu Item" />
80+
<MenuItem Header="Menu Item" />
81+
<MenuItem Header="-" />
82+
<MenuItem Header="Menu Item" />
83+
<MenuItem Header="Menu Item" />
84+
</MenuItem>
85+
<MenuItem Header="Short Menu (not working yet!)">
86+
<MenuItem Header="Menu Item" />
87+
<MenuItem Header="Menu Item" />
88+
</MenuItem>
89+
</Menu>
90+
91+
<Border Background="Gainsboro" />
92+
</DockPanel>
20993

21094
</UserControl>

samples/SampleApp/MainWindow.axaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
<TabItem Header="ComboBox">
2727
<demoPages:ComboBoxDemo />
2828
</TabItem>
29-
<!-- <TabItem Header="ContextMenu"> -->
30-
<!-- <demoPages:ContextMenuDemo /> -->
31-
<!-- </TabItem> -->
29+
<TabItem Header="ContextMenu" IsSelected="True">
30+
<demoPages:ContextMenuDemo />
31+
</TabItem>
3232
<TabItem Header="DataGrid">
3333
<demoPages:DataGridDemo>
3434
<demoPages:DataGridDemo.DataContext>
3535
<vm:DataGridViewModel />
3636
</demoPages:DataGridDemo.DataContext>
3737
</demoPages:DataGridDemo>
3838
</TabItem>
39-
<!-- <TabItem Header="Menu"> -->
40-
<!-- <demoPages:MenuDemo /> -->
41-
<!-- </TabItem> -->
42-
<TabItem Header="MenuFlyout" IsSelected="True">
39+
<TabItem Header="Menu" IsSelected="True">
40+
<demoPages:MenuDemo />
41+
</TabItem>
42+
<TabItem Header="MenuFlyout">
4343
<demoPages:MenuFlyoutDemo />
4444
</TabItem>
4545
<TabItem Header="TabControl">

src/MacOS.Avalonia.Theme/Accents/ThemeResources.axaml

+2
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,14 @@
210210
<Thickness x:Key="MenuFlyoutPresenterBorderThemeThickness">0</Thickness>
211211
<x:Double x:Key="MenuFlyoutSubItemPopupHorizontalOffset">-14</x:Double>
212212
<x:Double x:Key="MenuFlyoutSubItemPopupVerticalOffset">-7</x:Double>
213+
<x:Double x:Key="MenuPopupHorizontalOffset">-14</x:Double>
213214
<Thickness x:Key="MenuFlyoutPadding">5 2 5 2</Thickness>
214215
<Thickness x:Key="MenuFlyoutSeparatorThemePadding">8,5,8,5</Thickness>
215216
<Thickness x:Key="MenuIconPresenterMargin">0,0,4,0</Thickness>
216217
<Thickness x:Key="MenuInputGestureTextMargin">24,0,0,0</Thickness>
217218
<Thickness x:Key="MenuItemPadding">9 4 7 2</Thickness>
218219
<SolidColorBrush x:Key="SeparatorBrush" Color="{DynamicResource ForegroundColor}" Opacity="0.2" />
220+
<Thickness x:Key="MenuFlyoutScrollerMargin">0,4,0,4</Thickness>
219221

220222

221223
<!-- DEVELOPMENT ONLY -->

0 commit comments

Comments
 (0)