Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to change MenuItem style and control template. Actually you need to redefine 4 control templates for 4 different roles of MenuItem. This is a starting point code you need to change for your needs. Place it in your window resources or other appropriate place.</p> <pre><code>&lt;!-- SimpleStyles: MenuItem --&gt; &lt;Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}"&gt; &lt;Setter Property="Height" Value="1"/&gt; &lt;Setter Property="Margin" Value="0,4,0,4"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type Separator}"&gt; &lt;Border BorderBrush="#888888" BorderThickness="1"/&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;!-- TopLevelHeader --&gt; &lt;ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}"&gt; &lt;Border Name="Border" &gt; &lt;Grid&gt; &lt;ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" /&gt; &lt;Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade"&gt; &lt;Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="#FFFFFF" BorderBrush="#888888" BorderThickness="1" &gt; &lt;StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" /&gt; &lt;/Border&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsSuspendingPopupAnimation" Value="true"&gt; &lt;Setter TargetName="Popup" Property="PopupAnimation" Value="None"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsHighlighted" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#C0C0C0"/&gt; &lt;Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/&gt; &lt;/Trigger&gt; &lt;Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True"&gt; &lt;Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/&gt; &lt;Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter Property="Foreground" Value="#888888"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;!-- TopLevelItem --&gt; &lt;ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}"&gt; &lt;Border Name="Border" &gt; &lt;Grid&gt; &lt;ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" /&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsHighlighted" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#C0C0C0"/&gt; &lt;Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter Property="Foreground" Value="#888888"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;!-- SubmenuItem --&gt; &lt;ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}"&gt; &lt;Border Name="Border" &gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/&gt; &lt;ColumnDefinition Width="13"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon"/&gt; &lt;Border Name="Check" Width="13" Height="13" Visibility="Collapsed" Margin="6,0,6,0" Background="#C0C0C0" BorderThickness="1" BorderBrush="#404040"&gt; &lt;Path Name="CheckMark" Width="7" Height="7" Visibility="Hidden" SnapsToDevicePixels="False" Stroke="#404040" StrokeThickness="2" Data="M 0 0 L 7 7 M 0 7 L 7 0" /&gt; &lt;/Border&gt; &lt;ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="True"/&gt; &lt;TextBlock x:Name="InputGestureText" Grid.Column="2" Text="{TemplateBinding InputGestureText}" Margin="5,2,0,2" DockPanel.Dock="Right" /&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="Icon" Value="{x:Null}"&gt; &lt;Setter TargetName="Icon" Property="Visibility" Value="Hidden"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsChecked" Value="true"&gt; &lt;Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsCheckable" Value="true"&gt; &lt;Setter TargetName="Check" Property="Visibility" Value="Visible"/&gt; &lt;Setter TargetName="Icon" Property="Visibility" Value="Hidden"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsHighlighted" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#DDDDDD"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="#888888"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;!-- SubmenuHeader --&gt; &lt;ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}"&gt; &lt;Border Name="Border" &gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/&gt; &lt;ColumnDefinition Width="13"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon"/&gt; &lt;ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="True"/&gt; &lt;TextBlock x:Name="InputGestureText" Grid.Column="2" Text="{TemplateBinding InputGestureText}" Margin="5,2,2,2" DockPanel.Dock="Right"/&gt; &lt;Path Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 0 7 L 4 3.5 Z" Fill="#404040" /&gt; &lt;Popup Name="Popup" Placement="Right" HorizontalOffset="-4" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade"&gt; &lt;Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="#FFFFFF" BorderBrush="#888888" BorderThickness="1" &gt; &lt;StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" /&gt; &lt;/Border&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="Icon" Value="{x:Null}"&gt; &lt;Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsHighlighted" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#DDDDDD"/&gt; &lt;/Trigger&gt; &lt;Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True"&gt; &lt;Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="4"/&gt; &lt;Setter TargetName="SubmenuBorder" Property="Padding" Value="0,3,0,3"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="#888888"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;!-- MenuItem Style --&gt; &lt;Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True"/&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Role" Value="TopLevelHeader"&gt; &lt;Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}"/&gt; &lt;Setter Property="Grid.IsSharedSizeScope" Value="true"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="Role" Value="TopLevelItem"&gt; &lt;Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="Role" Value="SubmenuHeader"&gt; &lt;Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="Role" Value="SubmenuItem"&gt; &lt;Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload