-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
MaterialDesignTheme.Menu.xaml
318 lines (306 loc) · 20.9 KB
/
MaterialDesignTheme.Menu.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Font.xaml"/>
</ResourceDictionary.MergedDictionaries>
<converters:TextFieldHintVisibilityConverter x:Key="StringIsEmptyVisibilityConverter" IsEmptyValue="Collapsed" IsNotEmptyValue="Visible"/>
<converters:BrushRoundConverter x:Key="BrushRoundConverter"/>
<ContextMenu x:Key="MaterialDesignDefaultContextMenu">
<MenuItem Command="Cut">
<MenuItem.Icon>
<wpf:PackIcon Kind="ContentCut" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="Copy">
<MenuItem.Icon>
<wpf:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="Paste">
<MenuItem.Icon>
<wpf:PackIcon Kind="ContentPaste" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Command="SelectAll">
<MenuItem.Icon>
<wpf:PackIcon Kind="SelectAll" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
<Style x:Key="MaterialDesignSeparator" TargetType="{x:Type Separator}">
<Setter Property="Background" Value="{DynamicResource MaterialDesignSelection}"/>
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignSelection}"/>
<Setter Property="MinHeight" Value="1"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
<Rectangle Height="1" Fill="{TemplateBinding Background}"
HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MaterialDesignMenu" TargetType="{x:Type MenuBase}">
<Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}"/>
<Setter Property="FontFamily" Value="{StaticResource MaterialDesignFont}"/>
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}"/>
<Setter Property="TextBlock.FontSize" Value="15"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuBase}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MaterialDesignContextMenu" TargetType="{x:Type ContextMenu}" BasedOn="{StaticResource MaterialDesignMenu}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuBase}">
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Background="{TemplateBinding Background}"
Effect="{DynamicResource MaterialDesignShadowDepth1}"
Margin="3"
CornerRadius="2">
<Border Background="Transparent">
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
<Grid RenderOptions.ClearTypeHint="Enabled" Margin="0 16">
<ItemsPresenter x:Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Cycle"
Grid.IsSharedSizeScope="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</ScrollViewer>
</Border>
</Border>
</AdornerDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type MenuItem}" x:Key="MaterialDesignMenuItem" BasedOn="{x:Null}">
<Setter Property="Padding" Value="24 0 24 0"></Setter>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<ControlTemplate.Resources>
<Style TargetType="{x:Type wpf:PackIcon}" >
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
</Style>
</ControlTemplate.Resources>
<Grid ClipToBounds="True">
<Border x:Name="templateRoot"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True"/>
<Border x:Name="BackgroundRoot"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
SnapsToDevicePixels="True"
Opacity="0"/>
<wpf:Ripple Background="Transparent"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
Focusable="False"
Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}">
<Grid Height="{TemplateBinding Height}" Background="Transparent">
<Grid VerticalAlignment="Center"
Background="Transparent"
Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="IconGroup"/>
<ColumnDefinition Width="*" SharedSizeGroup="HeaderGroup"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid x:Name="IconWrapper" Visibility="Visible" Width="40">
<ContentPresenter x:Name="Icon"
Content="{TemplateBinding Icon}"
ContentSource="Icon"
HorizontalAlignment="Left" VerticalAlignment="Center"
Height="16" Width="16"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
<Grid x:Name="GlyphWrapper" Visibility="Collapsed" Width="40">
<Viewbox x:Name="GlyphPanel"
Width="16" Height="16"
HorizontalAlignment="Left"
Margin="0" Visibility="Collapsed" VerticalAlignment="Center"
FlowDirection="LeftToRight">
<Canvas Width="24" Height="24">
<Path Data="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"
x:Name="Glyph"
Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" />
</Canvas>
</Viewbox>
</Grid>
<Grid Grid.Column="1">
<ContentPresenter x:Name="BoldHeaderPresenter"
Visibility="Hidden"
TextBlock.FontWeight="Bold"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Content="{TemplateBinding Header}"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
ContentSource="Header"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center"/>
<ContentPresenter x:Name="HeaderPresenter"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Content="{TemplateBinding Header}"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
ContentSource="Header"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center"/>
</Grid>
<Grid x:Name="InputGestureTextWrapper"
Grid.Column="2"
Visibility="Collapsed">
<TextBlock Visibility="{TemplateBinding InputGestureText, Converter={StaticResource StringIsEmptyVisibilityConverter}}"
Margin="16 0 0 0"
VerticalAlignment="Center" HorizontalAlignment="Right"
Text="{TemplateBinding InputGestureText}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Foreground="{TemplateBinding Foreground}"/>
</Grid>
<Grid x:Name="SubBlock"
Grid.Column="2"
Visibility="Collapsed"
Margin="16 0 0 0">
<Path Width="5" Height="10"
Stretch="Uniform"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M0,16 L8,8 L0,0 Z"
Fill="{TemplateBinding Foreground}"
SnapsToDevicePixels="False"/>
</Grid>
</Grid>
</Grid>
</wpf:Ripple>
<Popup x:Name="PART_Popup"
AllowsTransparency="True"
Focusable="False"
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="Slide"
Placement="Bottom"
CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border x:Name="SubMenuBorder"
Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}"
Effect="{DynamicResource MaterialDesignShadowDepth1}"
CornerRadius="2">
<Border Background="Transparent">
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
<Grid RenderOptions.ClearTypeHint="Enabled" Margin="0 16">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRect"
Fill="{Binding Background, ElementName=SubMenuBorder}"
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Cycle"
Grid.IsSharedSizeScope="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</ScrollViewer>
</Border>
</Border>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<!--#region Roles Triggers -->
<Trigger Property="Role" Value="SubmenuHeader">
<Setter TargetName="SubBlock" Property="Visibility" Value="Visible" />
<Setter TargetName="PART_Popup" Property="Placement" Value="Right" />
<Setter Property="Height" Value="32"/>
<Setter TargetName="BoldHeaderPresenter" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="Role" Value="SubmenuItem">
<Setter Property="Height" Value="32"/>
<Setter TargetName="InputGestureTextWrapper" Property="Visibility" Value="Visible"/>
<Setter TargetName="BoldHeaderPresenter" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="Role" Value="TopLevelHeader">
<Setter Property="Grid.IsSharedSizeScope" Value="True"/>
<Setter Property="Padding" Value="16 0"/>
<Setter Property="Height" Value="48"/>
<Setter TargetName="templateRoot" Property="CornerRadius" Value="2"/>
<Setter TargetName="BackgroundRoot" Property="CornerRadius" Value="2"/>
</Trigger>
<Trigger Property="Role" Value="TopLevelItem">
<Setter Property="Padding" Value="16 0"/>
<Setter Property="Height" Value="48"/>
<Setter TargetName="templateRoot" Property="CornerRadius" Value="2"/>
<Setter TargetName="BackgroundRoot" Property="CornerRadius" Value="2"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Role" Value="TopLevelHeader"/>
<Condition Property="IsSubmenuOpen" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter TargetName="HeaderPresenter" Property="TextBlock.FontWeight" Value="Bold"/>
</MultiTrigger.Setters>
</MultiTrigger>
<!--#endregion-->
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
<Setter TargetName="SubMenuBorder" Property="Margin" Value="5"/>
</Trigger>
<Trigger Property="IsSuspendingPopupAnimation" Value="True">
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Visibility" TargetName="IconWrapper" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
</Trigger>
<Trigger Property="IsCheckable" Value="True">
<Setter Property="Visibility" TargetName="GlyphWrapper" Value="Visible"/>
<Setter Property="Visibility" TargetName="IconWrapper" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="BackgroundRoot" Property="Opacity" Value="0.13"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value=".56"/>
</Trigger>
<Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Static wpf:Spelling.SuggestionMenuItemStyleKey}" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=CommandParameter}" />
</Style>
<Style x:Key="{x:Static wpf:Spelling.IgnoreAllMenuItemStyleKey}" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="Header" Value="Ignore All" />
</Style>
<Style x:Key="{x:Static wpf:Spelling.NoSuggestionsMenuItemStyleKey}" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="Header" Value="(no spelling suggestions)" />
<Setter Property="IsEnabled" Value="False" />
</Style>
</ResourceDictionary>