<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
                    xmlns:themes="clr-namespace:XamlTheme">

    <SolidColorBrush x:Key="MenuItemHighlightedFill" Color="#F8F9FA"/>
    <Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>

    <!--TopLevelHeader-->
    <ControlTemplate x:Key="{x:Static themes:ResourceKeys.MenuItemTopLevelHeaderTemplateKey}" 
                     TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
            <DockPanel x:Name="Bg">
                <ContentPresenter x:Name="Icon" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                <Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" Visibility="Collapsed" VerticalAlignment="Center"/>
                <ContentPresenter ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
            </DockPanel>
            <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" HorizontalOffset="1" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom" VerticalOffset="-1">
                <mwt:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                    <Border BorderBrush="LightGray" BorderThickness="1" Background="#F1F1F1">
                        <ScrollViewer CanContentScroll="true" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" Margin="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
                        </ScrollViewer>
                    </Border>
                </mwt:SystemDropShadowChrome>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <Trigger Property="IsSubmenuOpen" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <!--
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="#FF9A9A9A"/>
                <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589"/>
            </Trigger>
            -->
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--TopLevelItem-->
    <ControlTemplate x:Key="{x:Static themes:ResourceKeys.MenuItemTopLevelItemTemplateKey}" 
                     TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
            <DockPanel x:Name="Bg">
                <ContentPresenter x:Name="Icon" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                <Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" Visibility="Collapsed" VerticalAlignment="Center"/>
                <ContentPresenter ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
            </DockPanel>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <!--
            <Trigger Property="IsEnabled" Value="false">  
                <Setter Property="Foreground" Value="#FF9A9A9A"/>
                <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589"/> 
            </Trigger>
            -->
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--SubmenuHeader-->
    <ControlTemplate x:Key="{x:Static themes:ResourceKeys.MenuItemSubmenuHeaderTemplateKey}" 
                     TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
            <Grid x:Name="Bg">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="4"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="37"/>
                    <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="17"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon" ContentSource="Icon" Margin="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                <Border x:Name="GlyphPanel" BorderBrush="#CDD3E6" BorderThickness="1" Background="#E6EFF4" CornerRadius="3" Height="22" Margin="1" Visibility="Hidden" Width="22">
                    <Path x:Name="Glyph" Data="{StaticResource Checkmark}" Fill="#0C12A1" FlowDirection="LeftToRight" Height="11" Width="9"/>
                </Border>
                <ContentPresenter Grid.Column="2" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  VerticalAlignment="Center"/>
                <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Text="{TemplateBinding InputGestureText}" Visibility="Collapsed" VerticalAlignment="Center"/>
                <Path Grid.Column="5" Data="M 0,0 L 4,3.5 L 0,7 Z" Fill="{TemplateBinding Foreground}" Margin="4,0,0,0" VerticalAlignment="Center"/>
            </Grid>
            <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" HorizontalOffset="-2" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3">
                <mwt:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                    <Border BorderBrush="LightGray" BorderThickness="1" Background="#F1F1F1">
                        <ScrollViewer CanContentScroll="true" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" Margin="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
                        </ScrollViewer>
                    </Border>
                </mwt:SystemDropShadowChrome>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
            </Trigger>
            <!--
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="#FF9A9A9A"/>
                <Setter Property="Background" TargetName="GlyphPanel" Value="#EEE9E9"/>
                <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#DBD6D6"/>
                <Setter Property="Fill" TargetName="Glyph" Value="#848589"/>
            </Trigger>
            -->
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--SubmenuItem-->
    <ControlTemplate x:Key="{x:Static themes:ResourceKeys.MenuItemSubmenuItemTemplateKey}" 
                     TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
            <Grid x:Name="Bg">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="4"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="37"/>
                    <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
                    <ColumnDefinition Width="17"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon" ContentSource="Icon" Margin="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                <Border x:Name="GlyphPanel" BorderBrush="#CDD3E6" BorderThickness="1" Background="#E6EFF4" CornerRadius="3" Height="22" Margin="1" Visibility="Hidden" Width="22">
                    <Path x:Name="Glyph" Data="{StaticResource Checkmark}" Fill="#0C12A1" FlowDirection="LeftToRight" Height="11" Width="9"/>
                </Border>
                <ContentPresenter Grid.Column="2" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
                <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter Property="Background" TargetName="Bg" Value="{StaticResource MenuItemHighlightedFill}"/>
            </Trigger>
            <!--
            <Trigger Property="IsEnabled" Value="false"> 
                <Setter Property="Foreground" Value="#FF9A9A9A"/>
                <Setter Property="Background" TargetName="GlyphPanel" Value="#EEE9E9"/>
                <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#DBD6D6"/>
                <Setter Property="Fill" TargetName="Glyph" Value="#848589"/>
            </Trigger>
            -->
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="{x:Static themes:ResourceKeys.MenuItemStyleKey}" TargetType="{x:Type MenuItem}">
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="MinHeight" Value="24"/>
        <Setter Property="Template" Value="{StaticResource {x:Static themes:ResourceKeys.MenuItemSubmenuItemTemplateKey}}"/>
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Padding" Value="7,2,8,3"/>
                <Setter Property="Template" Value="{StaticResource {x:Static themes:ResourceKeys.MenuItemTopLevelHeaderTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Padding" Value="7,2,8,3"/>
                <Setter Property="Template" Value="{StaticResource {x:Static themes:ResourceKeys.MenuItemTopLevelItemTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Padding" Value="2,3,2,3"/>
                <Setter Property="Template" Value="{StaticResource {x:Static themes:ResourceKeys.MenuItemSubmenuHeaderTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Padding" Value="2,3,2,3"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Opacity" Value="0.5"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Static themes:ResourceKeys.ContextMenuStyleKey}" TargetType="{x:Type ContextMenu}">
        <Setter Property="FontSize" Value="12"/>
        <Setter Property="Foreground" Value="#FF141414"/>
        <Setter Property="BorderBrush" Value="LightGray"/>
        <Setter Property="Background" Value="#E7E8EC"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Grid.IsSharedSizeScope" Value="True" />
        <Setter Property="HasDropShadow" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <mwt:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                        <Border Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                            </Grid>
                        </Border>
                    </mwt:SystemDropShadowChrome>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasDropShadow" Value="true">
                            <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                            <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>