-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
HamburgerMenuRipple.xaml
315 lines (290 loc) · 21 KB
/
HamburgerMenuRipple.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
<UserControl x:Class="MetroDemo.HamburgerMenuRipple"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:materialDesignConverters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:metroDemo="clr-namespace:MetroDemo"
d:DataContext="{d:DesignInstance metroDemo:MainWindowViewModel}"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Themes/HamburgerMenuTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- This is the template for the menu items. -->
<DataTemplate x:Key="MenuItemTemplate" DataType="{x:Type Controls:HamburgerMenuIconItem}">
<Grid Height="48">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{Binding Icon}"
Focusable="False"
IsTabStop="False" />
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
FontSize="16"
Text="{Binding Label}" />
</Grid>
</DataTemplate>
<ObjectDataProvider x:Key="DisplayModeEnumValues"
MethodName="GetValues"
ObjectType="{x:Type Controls:SplitViewDisplayMode}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Controls:SplitViewDisplayMode" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="VisibilityEnumValues"
MethodName="GetValues"
ObjectType="{x:Type Visibility}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Visibility" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<materialDesignConverters:BrushRoundConverter x:Key="BrushRoundConverter" />
<Style x:Key="HamburgerMenuCreatorsItemStyle"
BasedOn="{StaticResource MahApps.Styles.ListBoxItem.HamburgerMenuItem}"
TargetType="{x:Type ListBoxItem}">
<Setter Property="Controls:ItemHelper.ActiveSelectionBackgroundBrush" Value="Transparent" />
<Setter Property="Controls:ItemHelper.ActiveSelectionForegroundBrush" Value="{DynamicResource MahApps.Brushes.AccentBase}" />
<Setter Property="Controls:ItemHelper.DisabledForegroundBrush" Value="{DynamicResource MahApps.Brushes.Gray}" />
<Setter Property="Controls:ItemHelper.DisabledSelectedBackgroundBrush" Value="Transparent" />
<Setter Property="Controls:ItemHelper.DisabledSelectedForegroundBrush" Value="{DynamicResource MahApps.Brushes.Gray}" />
<Setter Property="Controls:ItemHelper.HoverBackgroundBrush" Value="{DynamicResource MahApps.Brushes.Gray9}" />
<Setter Property="Controls:ItemHelper.HoverSelectedBackgroundBrush" Value="{DynamicResource MahApps.Brushes.Gray9}" />
<Setter Property="Controls:ItemHelper.SelectedBackgroundBrush" Value="Transparent" />
<Setter Property="Controls:ItemHelper.SelectedForegroundBrush" Value="{DynamicResource MahApps.Brushes.AccentBase}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Background="{TemplateBinding Background}" RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Grid Margin="{TemplateBinding BorderThickness}">
<Grid HorizontalAlignment="Left"
VerticalAlignment="Center"
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:HamburgerMenu}}, Path=ShowSelectionIndicator, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Rectangle x:Name="SelectionIndicator"
Width="{DynamicResource HamburgerMenuSelectionIndicatorThemeWidth}"
Height="{DynamicResource HamburgerMenuSelectionIndicatorThemeHeight}"
Fill="{TemplateBinding Foreground}"
Focusable="False"
Opacity="0.0" />
</Grid>
<materialDesign:Ripple Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
Focusable="False"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:ItemHelper.SelectedForegroundBrush), Mode=OneWay}" />
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ItemHelper.SelectedBackgroundBrush), Mode=OneWay}" />
<Setter TargetName="SelectionIndicator" Property="Opacity" Value="1.0" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="Selector.IsSelectionActive" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:ItemHelper.ActiveSelectionForegroundBrush), Mode=OneWay}" />
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ItemHelper.ActiveSelectionBackgroundBrush), Mode=OneWay}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ItemHelper.HoverSelectedBackgroundBrush), Mode=OneWay}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsSelected" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ItemHelper.HoverBackgroundBrush), Mode=OneWay}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:ItemHelper.DisabledForegroundBrush), Mode=OneWay}" />
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:ItemHelper.DisabledBackgroundBrush), Mode=OneWay}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:ItemHelper.DisabledSelectedForegroundBrush), Mode=OneWay}" />
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:ItemHelper.DisabledSelectedBackgroundBrush), Mode=OneWay}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HamburgerMenuCreatorsStyle"
BasedOn="{StaticResource {x:Type Controls:HamburgerMenu}}"
TargetType="{x:Type Controls:HamburgerMenu}">
<Setter Property="ItemContainerStyle" Value="{StaticResource HamburgerMenuCreatorsItemStyle}" />
<Setter Property="OptionsItemContainerStyle" Value="{StaticResource HamburgerMenuCreatorsItemStyle}" />
<Setter Property="PaneBackground" Value="{DynamicResource MahApps.Brushes.ThemeBackground}" />
<Setter Property="PaneForeground" Value="{DynamicResource MahApps.Brushes.Text}" />
<Setter Property="ShowSelectionIndicator" Value="True" />
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="1"
MinWidth="230"
Margin="10 10 5 10"
Padding="0 0 5 0"
HorizontalContentAlignment="Stretch"
HorizontalScrollBarVisibility="Disabled">
<StackPanel Margin="0 0 0 10" Orientation="Vertical">
<Controls:ToggleSwitch Margin="0 10 0 5"
Header="IsPaneOpen:"
IsOn="{Binding ElementName=HamburgerMenuControl, Path=IsPaneOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Controls:MetroHeader Margin="0 10 0 5" Header="DisplayMode:">
<ComboBox MinWidth="150"
HorizontalAlignment="Left"
ItemsSource="{Binding Source={StaticResource DisplayModeEnumValues}}"
SelectedItem="{Binding ElementName=HamburgerMenuControl, Path=DisplayMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Controls:MetroHeader>
<Controls:MetroHeader Margin="0 10 0 5" Header="SelectedIndex:">
<Slider AutoToolTipPlacement="TopLeft"
Maximum="3"
Minimum="0"
Value="{Binding ElementName=HamburgerMenuControl, Path=SelectedIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Controls:MetroHeader>
<Controls:MetroHeader Margin="0 10 0 5" Header="CompactPaneLength:">
<Slider AutoToolTipPlacement="TopLeft"
Maximum="80"
Minimum="10"
Value="{Binding ElementName=HamburgerMenuControl, Path=CompactPaneLength, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Controls:MetroHeader>
<Controls:MetroHeader Margin="0 10 0 5" Header="OpenPaneLength:">
<Slider AutoToolTipPlacement="TopLeft"
Maximum="400"
Minimum="50"
Value="{Binding ElementName=HamburgerMenuControl, Path=OpenPaneLength, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Controls:MetroHeader>
<Controls:MetroHeader Margin="0 10 0 5" Header="HamburgerVisibility:">
<ComboBox MinWidth="150"
HorizontalAlignment="Left"
ItemsSource="{Binding Source={StaticResource VisibilityEnumValues}}"
SelectedItem="{Binding ElementName=HamburgerMenuControl, Path=HamburgerVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Controls:MetroHeader>
<Controls:MetroHeader Margin="0 10 0 5" Header="Hamburger Width / Height:">
<UniformGrid Columns="2">
<Slider Margin="0 0 5 0"
AutoToolTipPlacement="TopLeft"
Maximum="80"
Minimum="10"
Value="{Binding ElementName=HamburgerMenuControl, Path=HamburgerWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Slider Margin="5 0 0 0"
AutoToolTipPlacement="TopLeft"
Maximum="80"
Minimum="10"
Value="{Binding ElementName=HamburgerMenuControl, Path=HamburgerHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</UniformGrid>
</Controls:MetroHeader>
</StackPanel>
</ScrollViewer>
<Border Grid.Column="0"
Margin="10 10 0 10"
BorderBrush="{DynamicResource MahApps.Brushes.Gray7}"
BorderThickness="1">
<Controls:HamburgerMenu x:Name="HamburgerMenuControl"
HamburgerWidth="48"
IsPaneOpen="True"
ItemInvoked="HamburgerMenuControl_OnItemInvoked"
ItemTemplate="{StaticResource MenuItemTemplate}"
OptionsItemTemplate="{StaticResource MenuItemTemplate}"
SelectedIndex="0"
Style="{StaticResource HamburgerMenuCreatorsStyle}"
VerticalScrollBarOnLeftSide="False">
<!-- Items -->
<Controls:HamburgerMenu.ItemsSource>
<Controls:HamburgerMenuItemCollection>
<Controls:HamburgerMenuIconItem Icon="{iconPacks:Material Kind=Home}" Label="Home">
<Controls:HamburgerMenuIconItem.Tag>
<metroDemo:HomeView />
</Controls:HamburgerMenuIconItem.Tag>
</Controls:HamburgerMenuIconItem>
<Controls:HamburgerMenuIconItem Icon="{iconPacks:Material Kind=AccountCircle}" Label="Private">
<Controls:HamburgerMenuIconItem.Tag>
<metroDemo:PrivateView />
</Controls:HamburgerMenuIconItem.Tag>
</Controls:HamburgerMenuIconItem>
<Controls:HamburgerMenuIconItem Icon="{iconPacks:Octicons Kind=Briefcase}" Label="Briefcase">
<Controls:HamburgerMenuIconItem.Tag>
<UserControl>
<StackPanel Orientation="Vertical">
<Controls:ToggleSwitch Margin="0 0 0 5" Header="Lorem ipsum dolor sit amet, consectetur adipiscing elit" />
<Controls:ToggleSwitch Margin="0 0 0 5"
Header="Ut dictum arcu egestas aliquet elementum"
IsOn="True" />
<Controls:ToggleSwitch Margin="0 0 0 5" Header="Pellentesque ultricies metus quis dui luctus, vel faucibus risus rhoncus" />
</StackPanel>
</UserControl>
</Controls:HamburgerMenuIconItem.Tag>
</Controls:HamburgerMenuIconItem>
</Controls:HamburgerMenuItemCollection>
</Controls:HamburgerMenu.ItemsSource>
<!-- Options -->
<Controls:HamburgerMenu.OptionsItemsSource>
<Controls:HamburgerMenuItemCollection>
<Controls:HamburgerMenuIconItem Icon="{iconPacks:Material Kind=Settings}" Label="Settings">
<Controls:HamburgerMenuIconItem.Tag>
<metroDemo:SettingsView />
</Controls:HamburgerMenuIconItem.Tag>
</Controls:HamburgerMenuIconItem>
</Controls:HamburgerMenuItemCollection>
</Controls:HamburgerMenu.OptionsItemsSource>
<Controls:HamburgerMenu.ContentTemplate>
<DataTemplate DataType="{x:Type Controls:HamburgerMenuIconItem}">
<Grid Margin="20 0 10 0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="0 15 0 5"
Padding="0"
FontFamily="{DynamicResource MahApps.Fonts.Family.Header}"
FontSize="{DynamicResource MahApps.Font.Size.Header}"
Text="{Binding Label}" />
<ScrollViewer Grid.Row="1"
Focusable="False"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<ContentControl Content="{Binding Tag}" Focusable="False" />
</ScrollViewer>
</Grid>
</DataTemplate>
</Controls:HamburgerMenu.ContentTemplate>
</Controls:HamburgerMenu>
</Border>
</Grid>
</UserControl>