<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    mc:Ignorable="d">

    <Style TargetType="{x:Type Separator}">
        <Setter Property="Background" Value="{DynamicResource NormalBorderBrush}" />
        <Setter Property="Margin" Value="0,2,0,2" />
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}" 
                            Height="1"
                            SnapsToDevicePixels="true"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Menu}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Menu">
                    <StackPanel Orientation="Horizontal" IsItemsHost="True" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}" BasedOn="{StaticResource {x:Type Separator}}" />

    <!-- TopLevelHeader -->
    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="Border">
            <Grid>
                <Border x:Name="HoverBorder" Background="{DynamicResource HoverBrush}" Visibility="Collapsed"  />
                <TextBlock VerticalAlignment="Center" Padding="5" Style="{DynamicResource BaseTextBlockStyle}"
                           Foreground="{TemplateBinding Foreground}">
                    <ContentPresenter ContentSource="Header" RecognizesAccessKey="True" />
                </TextBlock>
                <Popup Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False">
                    <Border SnapsToDevicePixels="True" BorderBrush="{DynamicResource PopupBorderBrush}"
                            Background="{DynamicResource PopupBackgroundBrush}" BorderThickness="{DynamicResource PopupBorderThickness}">
                        <StackPanel Grid.IsSharedSizeScope="True" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Visibility" Value="Visible" TargetName="HoverBorder" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- TopLevelItem -->
    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="Border" BorderBrush="{DynamicResource PopupBorderBrush}"
                Background="{DynamicResource PopupBackgroundBrush}" BorderThickness="{DynamicResource PopupBorderThickness}">
            <ContentPresenter ContentSource="Header" RecognizesAccessKey="True" />
        </Border>
    </ControlTemplate>

    <!-- SubmenuHeader -->
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Grid Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup" />
                <ColumnDefinition Width="*" SharedSizeGroup="MenuItemIGTColumnGroup" />
                <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemShortcutColumnGroup" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border x:Name="HoverBorder" Grid.Column="0" Grid.ColumnSpan="4"
                    Background="{DynamicResource HoverBrush}" Visibility="Collapsed"  />
            <ContentPresenter x:Name="Icon" Grid.Column="0" Margin="4,0,-5,0"
                              MaxHeight="16" MaxWidth="16"
                              VerticalAlignment="Center" ContentSource="Icon" />
            <Grid x:Name="GlyphPanel" Grid.Column="0" Visibility="Collapsed"
                  Margin="5,0,-5,0" VerticalAlignment="Center">
                <TextBlock FontFamily="Marlett" Text="a" VerticalAlignment="Center" Style="{DynamicResource BaseTextBlockStyle}" />
            </Grid>
            <TextBlock Grid.Column="1" Padding="5" VerticalAlignment="Center" Style="{DynamicResource BaseTextBlockStyle}"
                       Foreground="{TemplateBinding Foreground}">
                <ContentPresenter RecognizesAccessKey="True" Margin="5,0,5,0" ContentSource="Header"/>
            </TextBlock>
            <TextBlock x:Name="GestureText" Grid.Column="2" Text="{TemplateBinding InputGestureText}"
                       TextAlignment="Left" HorizontalAlignment="Stretch" Margin="20,5,10,5"
                       VerticalAlignment="Center" Background="Transparent" Opacity="0.6"/>
            <Grid Grid.Column="3" Margin="0,0,5,0">
                <TextBlock FontFamily="Marlett" Text="4" VerticalAlignment="Center" Style="{DynamicResource BaseTextBlockStyle}" />
            </Grid>
            <Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right"
                   Focusable="False" AllowsTransparency="True">
                <Border BorderBrush="{DynamicResource PopupBorderBrush}" Background="{DynamicResource PopupBackgroundBrush}"
                        BorderThickness="{DynamicResource PopupBorderThickness}">
                    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                        <StackPanel Grid.IsSharedSizeScope="True" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </ScrollViewer>
                </Border>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" Value="Collapsed" TargetName="Icon" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="Icon" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Visibility" Value="Visible" TargetName="HoverBorder" />
            </Trigger>
            <Trigger Property="InputGestureText" Value="">
                <Setter Property="Visibility" Value="Collapsed" TargetName="GestureText" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- SubmenuItem -->
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="HoverBorder" Background="{DynamicResource HoverBrush}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup" />
                    <ColumnDefinition Width="*" SharedSizeGroup="MenuItemIGTColumnGroup" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemShortcutColumnGroup" />
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon" Grid.Column="0" Margin="4,0,-5,0"
                                  MaxHeight="16" MaxWidth="16"
                                  VerticalAlignment="Center" ContentSource="Icon" />
                <Grid x:Name="GlyphPanel" Grid.Column="0" Visibility="Collapsed" Margin="5,0,-5,0" VerticalAlignment="Center">
                    <TextBlock FontFamily="Marlett" Text="a" VerticalAlignment="Center" Style="{DynamicResource BaseTextBlockStyle}" />
                </Grid>
                <TextBlock VerticalAlignment="Center" Grid.Column="1" Margin="5,0,5,0" Padding="5" Style="{DynamicResource BaseTextBlockStyle}"
                           Foreground="{TemplateBinding Foreground}">
                    <ContentPresenter RecognizesAccessKey="True" ContentSource="Header"/>
                </TextBlock>
                <TextBlock x:Name="GestureText" Grid.Column="2" Text="{TemplateBinding InputGestureText}"
                           TextAlignment="Left" HorizontalAlignment="Stretch"
                           VerticalAlignment="Center" Margin="20,5,10,5" Opacity="0.6" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter Property="Visibility" Value="Collapsed" TargetName="Icon" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="Icon" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="False">
                <Setter Property="Background" Value="Transparent" TargetName="HoverBorder" />
            </Trigger>
            <Trigger Property="InputGestureText" Value="">
                <Setter Property="Visibility" Value="Collapsed" TargetName="GestureText" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource BaseStyle}">
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}" />
                <Setter Property="Grid.IsSharedSizeScope" Value="true" />
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.TopLevelItemTemplateKey}}" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.SubmenuItemTemplateKey}}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>