-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml
106 lines (95 loc) · 5.72 KB
/
MainWindow.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
<mah:MetroWindow x:Class="HamburguerConMvvm.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:converters="clr-namespace:HamburguerConMvvm.Converters"
xmlns:views="clr-namespace:HamburguerConMvvm.Views"
xmlns:viewModels="clr-namespace:HamburguerConMvvm.ViewModels"
xmlns:local="clr-namespace:HamburguerConMvvm"
mc:Ignorable="d" WindowStartupLocation="CenterScreen"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<viewModels:MainViewModel />
</Window.DataContext>
<Grid>
<Grid.Resources>
<converters:SelectedItemToContentConverter x:Key="SelectedItemToContentConverter" />
<!-- this is the template for the items (options too) -->
<DataTemplate x:Key="MenuItemTemplate" DataType="{x:Type mah:HamburgerMenuIconItem}">
<Grid x:Name="RootGrid"
Height="48"
Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:HamburgerMenu}}, Path=CompactPaneLength}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{Binding Icon}"
Focusable="False" />
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
FontSize="16"
Text="{Binding Label}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:HamburgerMenu}}, Path=IsPaneOpen}" Value="False">
<Setter TargetName="RootGrid" Property="ToolTip" Value="{Binding ToolTip, Mode=OneWay}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Grid.Resources>
<mah:HamburgerMenu x:Name="HamburgerMenuControl"
IsPaneOpen="True"
ItemTemplate="{StaticResource MenuItemTemplate}"
SelectedIndex="0"
DisplayMode="CompactInline">
<!-- Items -->
<mah:HamburgerMenu.ItemsSource>
<mah:HamburgerMenuItemCollection>
<mah:HamburgerMenuIconItem Icon="{iconPacks:Material Kind=Home}"
Label="Home">
<mah:HamburgerMenuIconItem.Tag>
<DataTemplate>
<views:HomeView DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=mah:MetroWindow}, Path=DataContext.HomeVM}" />
</DataTemplate>
</mah:HamburgerMenuIconItem.Tag>
</mah:HamburgerMenuIconItem>
<mah:HamburgerMenuIconItem Icon="{iconPacks:Material Kind=AccountKey}"
Label="Customer">
<mah:HamburgerMenuIconItem.Tag>
<DataTemplate>
<views:PrivateView DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=mah:MetroWindow}, Path=DataContext.PrivateVM}" />
</DataTemplate>
</mah:HamburgerMenuIconItem.Tag>
</mah:HamburgerMenuIconItem>
<mah:HamburgerMenuIconItem Icon="{iconPacks:Material Kind=MessageAlert}"
Label="Dialogs">
<mah:HamburgerMenuIconItem.Tag>
<DataTemplate>
<views:DialogsView DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=mah:MetroWindow}, Path=DataContext.DialogsVM}" />
</DataTemplate>
</mah:HamburgerMenuIconItem.Tag>
</mah:HamburgerMenuIconItem>
</mah:HamburgerMenuItemCollection>
</mah:HamburgerMenu.ItemsSource>
<!-- select the tag (ViewModel) of the selected item (options item) -->
<mah:HamburgerMenu.ContentTemplate>
<MultiBinding Converter="{StaticResource SelectedItemToContentConverter}">
<Binding FallbackValue="{x:Null}"
Mode="OneWay"
Path="SelectedItem.Tag"
RelativeSource="{RelativeSource Self}" />
<Binding FallbackValue="{x:Null}"
Mode="OneWay"
Path="SelectedOptionsItem.Tag"
RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</mah:HamburgerMenu.ContentTemplate>
</mah:HamburgerMenu>
</Grid>
</mah:MetroWindow>