Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving thin border around the menuitems
    primarykey
    data
    text
    <p>I based a custom menu on some code I once received. It looks OK, but I'm going crazy over how to remove the thin black border around the entire section of menuitems?! Where is this border/padding defined?</p> <p>Thanks to any WPF guru that might help me with this :)</p> <p><a href="http://img843.imageshack.us/img843/8813/testn.png">Valid XHTML http://img843.imageshack.us/img843/8813/testn.png</a></p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;SolidColorBrush x:Key="HighlightedBackgroundBrush" Color="#003466" /&gt; &lt;SolidColorBrush x:Key="MenuBackgroundBrush" Color="#003466" /&gt; &lt;SolidColorBrush x:Key="NormalBorderBrush" Color="#FFFFFFFF" /&gt; &lt;SolidColorBrush x:Key="SolidMenuFontBrush" Color="#FFFFFFFF" /&gt; &lt;SolidColorBrush x:Key="HighlightedText" Color="#FFFFFFFF" /&gt; &lt;Style x:Key="{x:Type Menu}" TargetType="{x:Type Menu}"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True"/&gt; &lt;Setter Property="SnapsToDevicePixels" Value="True"/&gt; &lt;Setter Property="Height" Value="25"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type Menu}"&gt; &lt;Border Background="{DynamicResource AppBackground}" BorderBrush="{DynamicResource AppBackground}" BorderThickness="1"&gt; &lt;StackPanel ClipToBounds="True" Orientation="Vertical" IsItemsHost="True"/&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type MenuItem}"&gt; &lt;Border x:Name="Border" BorderThickness="1"&gt; &lt;Grid Background="{DynamicResource AppBackground}"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition x:Name="Col0" MinWidth="17" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup"/&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="MenuTextColumnGroup"/&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup"/&gt; &lt;ColumnDefinition x:Name="Col3" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;!-- ContentPresenter to show an Icon if needed --&gt; &lt;ContentPresenter Grid.Column="0" Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon"/&gt; &lt;!-- Glyph is a checkmark if needed for a checkable menu --&gt; &lt;Grid Grid.Column="0" Visibility="Hidden" Margin="4,0,6,0" x:Name="GlyphPanel" VerticalAlignment="Center"&gt; &lt;Path x:Name="GlyphPanelpath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,2 L0,4.8 L2.5,7.4 L7.1,2.8 L7.1,0 L2.5,4.6 z" FlowDirection="LeftToRight"/&gt; &lt;/Grid&gt; &lt;!-- Content for the menu text etc --&gt; &lt;ContentPresenter Grid.Column="1" Margin="{TemplateBinding Padding}" x:Name="HeaderHost" RecognizesAccessKey="True" ContentSource="Header"/&gt; &lt;!-- Content for the menu IGT --&gt; &lt;ContentPresenter Grid.Column="2" Margin="8,1,8,1" x:Name="IGTHost" ContentSource="InputGestureText" VerticalAlignment="Center"/&gt; &lt;!-- Arrow drawn path which points to the next level of the menu --&gt; &lt;Grid Grid.Column="3" Margin="4,0,6,0" x:Name="ArrowPanel" VerticalAlignment="Center"&gt; &lt;Path x:Name="ArrowPanelPath" HorizontalAlignment="Right" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,0 L0,8 L4,4 z"/&gt; &lt;/Grid&gt; &lt;!-- The Popup is the body of the menu which expands down or across depending on the level of the item --&gt; &lt;Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right" x:Name="SubMenuPopup" Focusable="false" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"&gt; &lt;Border x:Name="SubMenuBorder" BorderBrush="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}" BorderThickness="1" Padding="2,2,2,2"&gt; &lt;Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True"&gt; &lt;!-- StackPanel holds children of the menu. This is set by IsItemsHost=True --&gt; &lt;StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;!-- These triggers re-configure the four arrangements of MenuItem to show different levels of menu via Role --&gt; &lt;ControlTemplate.Triggers&gt; &lt;!-- Role = TopLevelHeader : this is the root menu item in a menu; the Popup expands down --&gt; &lt;Trigger Property="Role" Value="TopLevelHeader"&gt; &lt;Setter Property="Padding" Value="6,1,6,1"/&gt; &lt;Setter Property="Placement" Value="Bottom" TargetName="SubMenuPopup"/&gt; &lt;Setter Property="MinWidth" Value="2" TargetName="Col0"/&gt; &lt;Setter Property="Width" Value="Auto" TargetName="Col3"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="GlyphPanel"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="IGTHost"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/&gt; &lt;/Trigger&gt; &lt;!-- Role = TopLevelItem : this is a child menu item from the top level without any child items--&gt; &lt;Trigger Property="Role" Value="TopLevelItem"&gt; &lt;Setter Property="Padding" Value="6,1,6,1"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/&gt; &lt;/Trigger&gt; &lt;!-- Role = SubMenuHeader : this is a child menu item which does not have children --&gt; &lt;Trigger Property="Role" Value="SubmenuHeader"&gt; &lt;Setter Property="DockPanel.Dock" Value="Top"/&gt; &lt;Setter Property="Padding" Value="0,2,0,2"/&gt; &lt;/Trigger&gt; &lt;!-- Role = SubMenuItem : this is a child menu item which has children--&gt; &lt;Trigger Property="Role" Value="SubmenuItem"&gt; &lt;Setter Property="DockPanel.Dock" Value="Top"/&gt; &lt;Setter Property="Padding" Value="0,2,0,2"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsSuspendingPopupAnimation" Value="true"&gt; &lt;Setter Property="PopupAnimation" Value="None" TargetName="SubMenuPopup"/&gt; &lt;/Trigger&gt; &lt;!-- If no Icon is present the we collapse the Icon Content --&gt; &lt;Trigger Property="Icon" Value="{x:Null}"&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/&gt; &lt;/Trigger&gt; &lt;!-- The GlyphPanel contains the CheckMark --&gt; &lt;Trigger Property="IsChecked" Value="true"&gt; &lt;Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel"/&gt; &lt;Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/&gt; &lt;/Trigger&gt; &lt;!-- Using the system colors for the Menu Highlight and IsEnabled--&gt; &lt;Trigger Property="IsHighlighted" Value="true"&gt; &lt;Setter Property="Background" Value="{DynamicResource HighlightedBackgroundBrush}" TargetName="Border"/&gt; &lt;Setter Property="Foreground" Value="{DynamicResource HighlightedText}"/&gt; &lt;Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}" TargetName="Border"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsHighlighted" Value="false"&gt; &lt;Setter Property="Background" Value="{DynamicResource AppBackground}" TargetName="Border"/&gt; &lt;Setter Property="Foreground" Value="{DynamicResource SolidMenuFontBrush}"/&gt; &lt;Setter Property="BorderBrush" Value="{DynamicResource AppBackground}" TargetName="Border"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="LightGray"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt; </code></pre>
    singulars
    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. 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