<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:MahApps.Metro.Controls">

    <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />

    <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>
    <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>
    <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
    <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>

    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
        <Setter Property="Background" Value="{DynamicResource MenuBackgroundBrush}" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Margin" Value="6 2 6 2" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Grid Margin="0 5 0 3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Rectangle Height="1"
                                   Margin="1 0 1 1"
                                   Fill="{DynamicResource GrayBrush7}"
                                   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                   UseLayoutRounding="True" />
                        <Rectangle Height="1"
                                   Margin="8 1 1 0"
                                   Fill="{DynamicResource WhiteBrush}"
                                   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                   UseLayoutRounding="True" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MetroMenu" TargetType="{x:Type Menu}">
        <Setter Property="Background" Value="{DynamicResource MenuBackgroundBrush}" />
        <Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}" />
        <Setter Property="FontSize" Value="{DynamicResource MenuFontSize}" />
        <Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}" />
        <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Menu}">
                    <Border Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <ItemsPresenter Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
    </Style>

    <Style x:Key="MetroContextMenu" TargetType="{x:Type ContextMenu}">
        <Setter Property="Background" Value="{DynamicResource ContextMenuBackgroundBrush}" />
        <Setter Property="Block.TextAlignment" Value="Left" />
        <Setter Property="BorderBrush" Value="{DynamicResource ContextMenuBorderBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="FontFamily" Value="Microsoft YaHei UI" />
        <Setter Property="FontSize" Value="{DynamicResource ContextMenuFontSize}" />
        <Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}" />
        <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
        <Setter Property="Grid.IsSharedSizeScope" Value="True" />
        <Setter Property="HasDropShadow" Value="True" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <Grid>
                        <Rectangle x:Name="LayoutRoot" Fill="{TemplateBinding Background}" />
                        <Border x:Name="Border"
                                Padding="{TemplateBinding Padding}"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">

                            <ScrollViewer x:Name="SubMenuScrollViewer"
                                          CanContentScroll="True"
                                          Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                                <ItemsPresenter x:Name="ItemsPresenter"
                                                Margin="0"
                                                Grid.IsSharedSizeScope="True"
                                                KeyboardNavigation.DirectionalNavigation="Cycle"
                                                KeyboardNavigation.TabNavigation="Cycle"
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasDropShadow" Value="True">
                            <Setter TargetName="Border" Property="Margin" Value="0 0 6 6" />
                            <Setter TargetName="LayoutRoot" Property="Effect">
                                <Setter.Value>
                                    <DropShadowEffect BlurRadius="4"
                                                      Direction="315"
                                                      Opacity="0.3"
                                                      ShadowDepth="2"
                                                      Color="{DynamicResource MenuShadowColor}" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="LayoutRoot" Property="Margin" Value="0 0 6 6" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
    </Style>

    <Style x:Key="MetroMenuItem" TargetType="{x:Type MenuItem}">
        <Setter Property="Background" Value="{DynamicResource MenuItemBackgroundBrush}" />
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="ScrollViewer.PanningMode" Value="Both" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Padding" Value="7 5 8 6" />
                <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Padding" Value="7 5 8 6" />
                <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Padding" Value="2 6 2 6" />
                <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Padding" Value="2 6 2 6" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Static controls:Spelling.SuggestionMenuItemStyleKey}"
           BasedOn="{StaticResource MetroMenuItem}"
           TargetType="{x:Type MenuItem}">
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=CommandParameter}" />
    </Style>

    <Style x:Key="{x:Static controls:Spelling.IgnoreAllMenuItemStyleKey}"
           BasedOn="{StaticResource MetroMenuItem}"
           TargetType="{x:Type MenuItem}">
        <Setter Property="Header" Value="Ignore All" />
    </Style>

    <Style x:Key="{x:Static controls:Spelling.NoSuggestionsMenuItemStyleKey}"
           BasedOn="{StaticResource MetroMenuItem}"
           TargetType="{x:Type MenuItem}">
        <Setter Property="Header" Value="(no spelling suggestions)" />
        <Setter Property="IsEnabled" Value="False" />
    </Style>

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

    <ContextMenu x:Key="TextBoxMetroContextMenu" Style="{StaticResource MetroContextMenu}">
        <MenuItem Command="ApplicationCommands.Cut" Style="{DynamicResource MetroMenuItem}" />
        <MenuItem Command="ApplicationCommands.Copy" Style="{DynamicResource MetroMenuItem}" />
        <MenuItem Command="ApplicationCommands.Paste" Style="{DynamicResource MetroMenuItem}" />
    </ContextMenu>

    <Style x:Key="MenuScrollButton"
           BasedOn="{x:Null}"
           TargetType="{x:Type RepeatButton}">
        <Setter Property="ClickMode" Value="Hover" />
        <Setter Property="MinHeight" Value="0" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <DockPanel Background="Transparent" SnapsToDevicePixels="True">
                        <Rectangle x:Name="R1"
                                   Width="1"
                                   DockPanel.Dock="Right"
                                   Fill="Transparent" />
                        <Rectangle x:Name="B1"
                                   Height="1"
                                   DockPanel.Dock="Bottom"
                                   Fill="Transparent" />
                        <Rectangle x:Name="L1"
                                   Width="1"
                                   DockPanel.Dock="Left"
                                   Fill="Transparent" />
                        <Rectangle x:Name="T1"
                                   Height="1"
                                   DockPanel.Dock="Top"
                                   Fill="Transparent" />
                        <ContentPresenter x:Name="ContentContainer"
                                          Margin="6"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center" />
                    </DockPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="B1" Property="Fill" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
                            <Setter TargetName="L1" Property="Fill" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" />
                            <Setter TargetName="R1" Property="Fill" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
                            <Setter TargetName="T1" Property="Fill" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}"
           BasedOn="{x:Null}"
           TargetType="{x:Type ScrollViewer}">
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid SnapsToDevicePixels="True">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Border Grid.Row="1" Grid.Column="0">
                            <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
                        </Border>
                        <RepeatButton Grid.Row="0"
                                      Grid.Column="0"
                                      Command="{x:Static ScrollBar.LineUpCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="False"
                                      Style="{StaticResource MenuScrollButton}">
                            <RepeatButton.Visibility>
                                <MultiBinding Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="0"
                                              FallbackValue="Visibility.Collapsed">
                                    <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Data="{StaticResource UpArrow}" Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
                        </RepeatButton>
                        <RepeatButton Grid.Row="2"
                                      Grid.Column="0"
                                      Command="{x:Static ScrollBar.LineDownCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="False"
                                      Style="{StaticResource MenuScrollButton}">
                            <RepeatButton.Visibility>
                                <MultiBinding Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="100"
                                              FallbackValue="Visibility.Collapsed">
                                    <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Data="{StaticResource DownArrow}" Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
                        </RepeatButton>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
    </Style>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" TargetType="{x:Type ContentControl}">
        <Border Background="{DynamicResource SubMenuBackgroundBrush}"
                BorderBrush="{DynamicResource SubMenuBorderBrush}"
                BorderThickness="1">
            <ContentPresenter />
        </Border>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="True">
            <Rectangle x:Name="Bg"
                       Margin="1"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
            <DockPanel>
                <ContentPresenter x:Name="Icon"
                                  Margin="4 0 6 0"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <Path x:Name="GlyphPanel"
                      Margin="8 0 0 0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed" />
                <ContentPresenter Margin="{TemplateBinding Padding}"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </DockPanel>
            <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Focusable="False"
                   HorizontalOffset="1"
                   IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   Placement="Bottom"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   VerticalOffset="-1">
                <Grid>
                    <Rectangle x:Name="LayoutRoot" Fill="{TemplateBinding Background}" />
                    <ContentControl x:Name="SubMenuBorder"
                                    IsTabStop="False"
                                    Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                        <ScrollViewer x:Name="SubMenuScrollViewer"
                                      CanContentScroll="True"
                                      Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <ItemsPresenter x:Name="ItemsPresenter"
                                            Margin="0"
                                            Grid.IsSharedSizeScope="True"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            KeyboardNavigation.TabNavigation="Cycle"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </ContentControl>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None" />
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="True">
                <Setter TargetName="LayoutRoot" Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect BlurRadius="4"
                                          Direction="315"
                                          Opacity="0.3"
                                          ShadowDepth="2"
                                          Color="{DynamicResource MenuShadowColor}" />
                    </Setter.Value>
                </Setter>
                <Setter TargetName="LayoutRoot" Property="Margin" Value="0 0 6 6" />
                <Setter TargetName="SubMenuBorder" Property="Margin" Value="0 0 6 6" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource TopMenuItemSelectionStroke}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="True">
                <Setter TargetName="Bg" Property="Fill" Value="{DynamicResource TopMenuItemPressedFill}" />
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource TopMenuItemPressedStroke}" />
            </Trigger>
            <Trigger Property="IsSubmenuOpen" Value="True">
                <Setter TargetName="Bg" Property="Fill" Value="{DynamicResource TopMenuItemPressedFill}" />
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource TopMenuItemPressedStroke}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource DisabledMenuItemForeground}" />
                <Setter TargetName="GlyphPanel" Property="Fill" Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="True">
            <Rectangle x:Name="Bg"
                       Margin="1"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
            <DockPanel>
                <ContentPresenter x:Name="Icon"
                                  Margin="4 0 6 0"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <Path x:Name="GlyphPanel"
                      Margin="8 0 0 0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed" />
                <ContentPresenter Margin="{TemplateBinding Padding}"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </DockPanel>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource TopMenuItemSelectionStroke}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="True">
                <Setter TargetName="Bg" Property="Fill" Value="{DynamicResource TopMenuItemPressedFill}" />
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource TopMenuItemPressedStroke}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource DisabledMenuItemForeground}" />
                <Setter TargetName="GlyphPanel" Property="Fill" Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="True">
            <Rectangle x:Name="Bg"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      MinWidth="24"
                                      SharedSizeGroup="MenuItemIconColumnGroup" />
                    <ColumnDefinition Width="4" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="6" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />
                    <ColumnDefinition Width="17" />
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon"
                                  Margin="1"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <Path x:Name="GlyphPanel"
                      Margin="5 0 0 0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed" />
                <ContentPresenter Grid.Column="2"
                                  Margin="{TemplateBinding Padding}"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <TextBlock Grid.Column="4"
                           Margin="{TemplateBinding Padding}"
                           Text="{TemplateBinding InputGestureText}"
                           Visibility="Collapsed" />
                <Path Grid.Column="5"
                      Margin="4 0 0 0"
                      VerticalAlignment="Center"
                      Data="{StaticResource RightArrow}"
                      Fill="{DynamicResource RightArrowFill}" />
            </Grid>
            <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Focusable="False"
                   HorizontalOffset="-2"
                   IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   Placement="Right"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   VerticalOffset="-3">
                <Grid>
                    <Rectangle x:Name="LayoutRoot" Fill="{TemplateBinding Background}" />
                    <ContentControl x:Name="SubMenuBorder"
                                    IsTabStop="False"
                                    Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                        <ScrollViewer x:Name="SubMenuScrollViewer"
                                      CanContentScroll="True"
                                      Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <ItemsPresenter x:Name="ItemsPresenter"
                                            Margin="0"
                                            Grid.IsSharedSizeScope="True"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            KeyboardNavigation.TabNavigation="Cycle"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </ContentControl>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None" />
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="True">
                <Setter TargetName="LayoutRoot" Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect BlurRadius="4"
                                          Direction="315"
                                          Opacity="0.3"
                                          ShadowDepth="2"
                                          Color="{DynamicResource MenuShadowColor}" />
                    </Setter.Value>
                </Setter>
                <Setter TargetName="LayoutRoot" Property="Margin" Value="0 0 6 6" />
                <Setter TargetName="SubMenuBorder" Property="Margin" Value="0 0 6 6" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Bg" Property="Fill" Value="{DynamicResource MenuItemSelectionFill}" />
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource MenuItemSelectionStroke}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource DisabledMenuItemForeground}" />
                <Setter TargetName="GlyphPanel" Property="Fill" Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <Grid SnapsToDevicePixels="True">
            <Rectangle x:Name="Bg"
                       Fill="{TemplateBinding Background}"
                       Stroke="{TemplateBinding BorderBrush}"
                       StrokeThickness="1" />
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      MinWidth="24"
                                      SharedSizeGroup="MenuItemIconColumnGroup" />
                    <ColumnDefinition Width="4" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="6" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />
                    <ColumnDefinition Width="17" />
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Icon"
                                  Margin="1"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <Path x:Name="GlyphPanel"
                      Margin="5 0 0 0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="{StaticResource Checkmark}"
                      Fill="{DynamicResource CheckmarkFill}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed" />
                <ContentPresenter Grid.Column="2"
                                  Margin="{TemplateBinding Padding}"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <TextBlock Grid.Column="4"
                           Margin="{TemplateBinding Padding}"
                           Text="{TemplateBinding InputGestureText}" />
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Bg" Property="Fill" Value="{DynamicResource MenuItemSelectionFill}" />
                <Setter TargetName="Bg" Property="Stroke" Value="{DynamicResource MenuItemSelectionStroke}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource DisabledMenuItemForeground}" />
                <Setter TargetName="GlyphPanel" Property="Fill" Value="{DynamicResource DisabledMenuItemGlyphPanel}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

</ResourceDictionary>
