Hello,
I need to build a context menu with black background without and icon space for the menu items (on the lefthand side). I am doing this in XAML as follows:
<ContextMenu Style="{StaticResource ResourceKey=PopupMenu}" x:Key="cmContextMenu" Foreground="#FFD9680D"><ContextMenu.Resources><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFD9680D"/><SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/></ContextMenu.Resources><MenuItem Style="{StaticResource ResourceKey=PopupMenuItem}" Header="Item1" Click="MenuItem_Click1" BorderBrush="Black" /><MenuItem Style="{StaticResource ResourceKey=PopupMenuItem}" Header="Item2" Click="Menuitem_Click2" BorderBrush="Black"/></ContextMenu> And the style for the context menu id defined as follows <!--Context Menu Item--><Style BasedOn="{StaticResource {x:Type MenuItem}}" TargetType="{x:Type MenuItem}" x:Key="PopupMenuItem"><Setter Property="OverridesDefaultStyle" Value="True"/><Setter Property="BorderBrush" Value="Black"></Setter><Setter Property="BorderThickness" Value="0,1,0,0"></Setter><Setter Property="Foreground" Value="White"></Setter><Setter Property="Margin" Value="-15,0,0,0"></Setter></Style><!--Context Menu--><Style BasedOn ="{StaticResource {x:Type ContextMenu}}" TargetType="{x:Type ContextMenu}" x:Key="PopupMenu"><Setter Property="OverridesDefaultStyle" Value="True"/><Setter Property="Background" Value="#FF5F5F5F"></Setter><Setter Property="BorderBrush" Value="Black"></Setter><Setter Property="BorderThickness" Value="1,0,1,1"></Setter><Setter Property="FontFamily" Value="R_Ansi"></Setter><Setter Property="ContextMenu.Margin" Value="0,0,0,0"></Setter><Setter Property="TextElement.Background" Value="White"></Setter><Setter Property="TextBlock.Background" Value="White"></Setter></Style>
The above seem to work OK in my WPF application (code in c# in VS2013 on windows 7 professional) if the desktop theme is set to "classic" look. But when I select the windows 7 theme a white strip (the incon space for the menuitem) appears. I can get rid off it by setting the Margin for contextmenu to -40,0,0,0 while using Windows 7 default theme. However, this solution is not really very elegant and neither very portable as because if I refer back to windows "classic" theme the contextmenu appears very odd with part of the text in menuitems chopped off.
I have done lot of searching on the internet about the white strip appearing on the contextmenu and the solution provided seem to be vary. My problem is quite different to those reported. I am still not sure why operating system theme should affect my application in this way since I am using OverrideDefaultStyle, which should result in my style being used.
So I am not sure why the windows theme style is overriding my settings for the contextmenu.
Any help would be appreciated.
Thanks.
WazedLM