Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As promised, here's the code. Thanks for your help Jay, lead me in the right direction to finally find an answer on MSDN <a href="http://msdn.microsoft.com/en-us/library/ms752296.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms752296.aspx</a> MenuItem and ContextMenu control the styling for the base menu, and the other two are for the submenu items. Jay's way may have worked, but I couldn't get it to unfortunately. This works perfectly though, and probably allows for much more control over the submenus styling. </p> <pre><code> &lt;UserControl.Resources&gt; &lt;!-- Separator --&gt; &lt;Style TargetType="{x:Type Separator}" x:Key="SeparatorStyle"&gt; &lt;Setter Property="Height" Value="1" /&gt; &lt;Setter Property="Background" Value="#0f3c5a" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type Separator}"&gt; &lt;Rectangle Height="{TemplateBinding Height}" Fill="White" /&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;!--Outer menu items--&gt; &lt;Style TargetType="{x:Type MenuItem}"&gt; &lt;Setter Property="Background" Value="#0f3c5a"&gt;&lt;/Setter&gt; &lt;Setter Property="Foreground" Value="White"&gt;&lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsHighlighted" Value="True"&gt; &lt;Setter Property="Background" Value="Black"&gt;&lt;/Setter&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter Property="Foreground" Value="LightGray"&gt;&lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;!-- Outer menu --&gt; &lt;Style TargetType="{x:Type ContextMenu}"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True" /&gt; &lt;Setter Property="SnapsToDevicePixels" Value="True" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ContextMenu}"&gt; &lt;!--Here is where you change the border thickness to zero on the menu--&gt; &lt;Border BorderThickness="0" x:Name="Border" Background="Transparent"&gt; &lt;StackPanel ClipToBounds="True" Orientation="Vertical" IsItemsHost="True" /&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#0f3c5a" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&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="#0f3c5a" BorderThickness="1" BorderBrush="#5082a4"&gt; &lt;Path Name="CheckMark" Width="7" Height="7" Visibility="Hidden" SnapsToDevicePixels="False" Stroke="#5082a4" 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="#5082a4" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="#0f3c5a" /&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="#0f3c5a" /&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="#0f3c5a" BorderBrush="#0f3c5a" 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="#5082a4" /&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="#0f3c5a" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&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