Themes/MaterialDesignTheme.Menu.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
                    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Font.xaml" />
  </ResourceDictionary.MergedDictionaries>
 
  <ContextMenu x:Key="MaterialDesignDefaultContextMenu" FontFamily="{Binding PlacementTarget.FontFamily, RelativeSource={RelativeSource Self}}">
    <MenuItem Command="Cut">
      <MenuItem.Icon>
        <wpf:PackIcon Kind="ContentCut" />
      </MenuItem.Icon>
    </MenuItem>
    <MenuItem Command="Copy">
      <MenuItem.Icon>
        <wpf:PackIcon Kind="ContentCopy" />
      </MenuItem.Icon>
    </MenuItem>
    <MenuItem Command="Paste">
      <MenuItem.Icon>
        <wpf:PackIcon Kind="ContentPaste" />
      </MenuItem.Icon>
    </MenuItem>
    <Separator />
    <MenuItem Command="SelectAll">
      <MenuItem.Icon>
        <wpf:PackIcon Kind="SelectAll" />
      </MenuItem.Icon>
    </MenuItem>
  </ContextMenu>
 
  <Style x:Key="MaterialDesignSeparator" TargetType="{x:Type Separator}">
    <Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.Separator.Background}" />
    <Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.Separator.Background}" />
    <Setter Property="Height" Value="16" />
    <Setter Property="MinHeight" Value="1" />
    <Setter Property="SnapsToDevicePixels" Value="true" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Separator}">
          <Rectangle Height="1"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Center"
                     Fill="{TemplateBinding Background}" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
 
  <Style x:Key="MaterialDesignMenuItem"
         TargetType="{x:Type MenuItem}"
         BasedOn="{x:Null}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="Padding" Value="24,0,24,0" />
    <Setter Property="wpf:MenuItemAssist.HighlightedBackground" Value="{Binding Foreground, RelativeSource={RelativeSource Self}, Converter={x:Static converters:BrushOpacityConverter.Instance}, ConverterParameter=0.13}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type MenuItem}">
          <ControlTemplate.Resources>
            <Style TargetType="wpf:PackIcon">
              <Setter Property="FrameworkElement.Height" Value="16" />
              <Setter Property="FrameworkElement.Width" Value="16" />
            </Style>
          </ControlTemplate.Resources>
          <Grid ClipToBounds="True">
            <Border x:Name="templateRoot"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    SnapsToDevicePixels="True" />
            <Border x:Name="BackgroundRoot"
                    Background="{Binding Path=(wpf:MenuItemAssist.HighlightedBackground), RelativeSource={RelativeSource TemplatedParent}}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    SnapsToDevicePixels="True"
                    Visibility="Hidden" />
            <wpf:Ripple HorizontalContentAlignment="Stretch"
                        VerticalContentAlignment="Stretch"
                        Background="Transparent"
                        Feedback="{TemplateBinding Foreground, Converter={x:Static converters:BrushRoundConverter.Instance}}"
                        Focusable="False">
              <Grid Height="{TemplateBinding Height}" Background="Transparent">
                <Grid Margin="{TemplateBinding Padding}"
                      VerticalAlignment="Center"
                      Background="Transparent">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="IconGroup" />
                    <ColumnDefinition Width="*" SharedSizeGroup="HeaderGroup" />
                    <ColumnDefinition Width="*" />
                  </Grid.ColumnDefinitions>
                  <Grid x:Name="IconWrapper"
                        Width="40"
                        Visibility="Visible">
                    <ContentPresenter x:Name="Icon"
                                      Width="16"
                                      Height="16"
                                      HorizontalAlignment="Left"
                                      VerticalAlignment="Center"
                                      Content="{TemplateBinding Icon}"
                                      ContentSource="Icon"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                  </Grid>
                  <Grid x:Name="GlyphWrapper"
                        Width="40"
                        Visibility="Collapsed">
                    <Viewbox x:Name="GlyphPanel"
                             Width="16"
                             Height="16"
                             Margin="0"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Center"
                             FlowDirection="LeftToRight"
                             Visibility="Collapsed">
                      <Canvas Width="24" Height="24">
                        <Path x:Name="Glyph"
                              Data="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"
                              Fill="{TemplateBinding Foreground}"
                              FlowDirection="LeftToRight" />
                      </Canvas>
                    </Viewbox>
                  </Grid>
                  <Grid Grid.Column="1">
                    <ContentPresenter x:Name="BoldHeaderPresenter"
                                      VerticalAlignment="Center"
                                      Content="{TemplateBinding Header}"
                                      ContentSource="Header"
                                      ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                      ContentTemplate="{TemplateBinding HeaderTemplate}"
                                      RecognizesAccessKey="True"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                      TextBlock.FontWeight="Bold"
                                      Visibility="Hidden" />
                    <ContentPresenter x:Name="HeaderPresenter"
                                      VerticalAlignment="Center"
                                      Content="{TemplateBinding Header}"
                                      ContentSource="Header"
                                      ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                      ContentTemplate="{TemplateBinding HeaderTemplate}"
                                      RecognizesAccessKey="True"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                  </Grid>
                  <Grid x:Name="InputGestureTextWrapper"
                        Grid.Column="2"
                        Visibility="Collapsed">
                    <TextBlock Margin="16,0,0,0"
                               HorizontalAlignment="Right"
                               VerticalAlignment="Center"
                               Foreground="{TemplateBinding Foreground}"
                               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                               Text="{TemplateBinding InputGestureText}"
                               Visibility="{TemplateBinding InputGestureText, Converter={x:Static converters:TextFieldHintVisibilityConverter.IsEmptyInstance}}" />
                  </Grid>
                  <Grid x:Name="SubBlock"
                        Grid.Column="2"
                        Margin="16,0,0,0"
                        Visibility="Collapsed">
                    <Path Width="5"
                          Height="10"
                          HorizontalAlignment="Right"
                          VerticalAlignment="Center"
                          Data="M0,16 L8,8 L0,0 Z"
                          Fill="{TemplateBinding Foreground}"
                          SnapsToDevicePixels="False"
                          Stretch="Uniform" />
                  </Grid>
                </Grid>
              </Grid>
            </wpf:Ripple>
            <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}"
                   Focusable="False"
                   IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   Placement="Bottom"
                   PopupAnimation="Slide">
              <Border x:Name="SubMenuBorder"
                      Background="{DynamicResource MaterialDesign.Brush.Background}"
                      CornerRadius="2"
                      Effect="{DynamicResource MaterialDesignShadowDepth1}">
                <Border Background="{TemplateBinding Background}" CornerRadius="2">
 
                  <Border Background="Transparent">
                    <ScrollViewer x:Name="SubMenuScrollViewer"
                                  Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"
                                  wpf:ScrollViewerAssist.IgnorePadding="{Binding Path=(wpf:ScrollViewerAssist.IgnorePadding), RelativeSource={RelativeSource TemplatedParent}}"
                                  wpf:ScrollViewerAssist.PaddingMode="{Binding Path=(wpf:ScrollViewerAssist.PaddingMode), RelativeSource={RelativeSource TemplatedParent}}">
                      <Grid Margin="{Binding RelativeSource={RelativeSource Mode=Self}, Path=(wpf:MenuAssist.MenuItemsPresenterMargin)}" RenderOptions.ClearTypeHint="Enabled">
                        <Canvas Width="0"
                                Height="0"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Top">
                          <Rectangle x:Name="OpaqueRect"
                                     Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
                                     Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
                                     Fill="Transparent" />
                        </Canvas>
                        <ItemsPresenter x:Name="ItemsPresenter"
                                        Grid.IsSharedSizeScope="True"
                                        KeyboardNavigation.DirectionalNavigation="Cycle"
                                        KeyboardNavigation.TabNavigation="Cycle"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                      </Grid>
                    </ScrollViewer>
                  </Border>
                </Border>
              </Border>
            </Popup>
          </Grid>
          <ControlTemplate.Triggers>
            <!--#region Roles Triggers-->
            <Trigger Property="Role" Value="SubmenuHeader">
              <Setter Property="Height" Value="32" />
              <Setter TargetName="BoldHeaderPresenter" Property="Visibility" Value="Collapsed" />
              <Setter TargetName="PART_Popup" Property="Placement" Value="Right" />
              <Setter TargetName="PART_Popup" Property="VerticalOffset" Value="-16" />
              <Setter TargetName="SubBlock" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
              <Setter Property="Height" Value="32" />
              <Setter TargetName="BoldHeaderPresenter" Property="Visibility" Value="Collapsed" />
              <Setter TargetName="InputGestureTextWrapper" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="Role" Value="TopLevelHeader">
              <Setter Property="Grid.IsSharedSizeScope" Value="True" />
              <Setter Property="Height" Value="{Binding Path=(wpf:MenuAssist.TopLevelMenuItemHeight), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}" />
              <Setter Property="Padding" Value="16,0" />
              <Setter TargetName="BackgroundRoot" Property="CornerRadius" Value="2" />
              <Setter TargetName="templateRoot" Property="CornerRadius" Value="2" />
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
              <Setter Property="Height" Value="{Binding Path=(wpf:MenuAssist.TopLevelMenuItemHeight), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}" />
              <Setter Property="Padding" Value="16,0" />
              <Setter TargetName="BackgroundRoot" Property="CornerRadius" Value="2" />
              <Setter TargetName="templateRoot" Property="CornerRadius" Value="2" />
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="Role" Value="TopLevelHeader" />
                <Condition Property="IsSubmenuOpen" Value="True" />
              </MultiTrigger.Conditions>
              <MultiTrigger.Setters>
                <Setter TargetName="HeaderPresenter" Property="TextBlock.FontWeight" Value="Bold" />
              </MultiTrigger.Setters>
            </MultiTrigger>
            <!--#endregion-->
 
            <Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="True">
              <Setter TargetName="SubMenuBorder" Property="Margin" Value="5" />
            </Trigger>
 
            <Trigger Property="IsSuspendingPopupAnimation" Value="True">
              <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None" />
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
              <Setter TargetName="IconWrapper" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
              <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsCheckable" Value="True">
              <Setter TargetName="GlyphWrapper" Property="Visibility" Value="Visible" />
              <Setter TargetName="IconWrapper" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
              <Setter TargetName="BackgroundRoot" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Opacity" Value=".56" />
            </Trigger>
            <Trigger SourceName="SubMenuScrollViewer" Property="CanContentScroll" Value="False">
              <Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}" />
              <Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
 
  <Style x:Key="MaterialDesignMenu" TargetType="{x:Type MenuBase}">
    <Style.Resources>
      <Style TargetType="MenuItem" BasedOn="{StaticResource MaterialDesignMenuItem}" />
    </Style.Resources>
 
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="FontFamily" Value="{StaticResource MaterialDesignFont}" />
    <Setter Property="Foreground" Value="{DynamicResource MaterialDesign.Brush.Foreground}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type MenuBase}">
          <Border Padding="{TemplateBinding Padding}"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  SnapsToDevicePixels="true">
            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="TextBlock.FontSize" Value="15" />
    <Setter Property="UseLayoutRounding" Value="True" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="wpf:MenuAssist.TopLevelMenuItemHeight" Value="48" />
  </Style>
 
  <Style x:Key="MaterialDesignContextMenu"
         TargetType="{x:Type ContextMenu}"
         BasedOn="{StaticResource MaterialDesignMenu}">
    <Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.Background}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type MenuBase}">
          <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
            <Grid>
              <Border Margin="3"
                      Background="{TemplateBinding Background}"
                      CornerRadius="2"
                      Effect="{DynamicResource MaterialDesignShadowDepth1}" />
 
              <Border Margin="3" Background="Transparent">
                <ScrollViewer x:Name="SubMenuScrollViewer"
                              Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"
                              wpf:ScrollViewerAssist.IgnorePadding="{Binding Path=(wpf:ScrollViewerAssist.IgnorePadding), RelativeSource={RelativeSource TemplatedParent}}"
                              wpf:ScrollViewerAssist.PaddingMode="{Binding Path=(wpf:ScrollViewerAssist.PaddingMode), RelativeSource={RelativeSource TemplatedParent}}">
                  <Grid Margin="{Binding RelativeSource={RelativeSource Mode=Self}, Path=(wpf:MenuAssist.MenuItemsPresenterMargin)}" RenderOptions.ClearTypeHint="Enabled">
                    <ItemsPresenter x:Name="ItemsPresenter"
                                    Grid.IsSharedSizeScope="True"
                                    KeyboardNavigation.DirectionalNavigation="Cycle"
                                    KeyboardNavigation.TabNavigation="Cycle"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                  </Grid>
                </ScrollViewer>
              </Border>
            </Grid>
          </AdornerDecorator>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
 
 
  <Style x:Key="{x:Static wpf:Spelling.SuggestionMenuItemStyleKey}"
         TargetType="{x:Type MenuItem}"
         BasedOn="{StaticResource MaterialDesignMenuItem}">
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=CommandParameter}" />
  </Style>
 
  <Style x:Key="{x:Static wpf:Spelling.IgnoreAllMenuItemStyleKey}"
         TargetType="{x:Type MenuItem}"
         BasedOn="{StaticResource MaterialDesignMenuItem}">
    <Setter Property="Header" Value="Ignore All" />
  </Style>
 
  <Style x:Key="{x:Static wpf:Spelling.NoSuggestionsMenuItemStyleKey}"
         TargetType="{x:Type MenuItem}"
         BasedOn="{StaticResource MaterialDesignMenuItem}">
    <Setter Property="Header" Value="(no spelling suggestions)" />
    <Setter Property="IsEnabled" Value="False" />
  </Style>
</ResourceDictionary>