C#C
C#2y ago
stigzler

WPF ContextMenu background color problems

I'm trying to implement a dark theme on a ContexMenu. I'm getting some strange artefacts around the icon column:

<!-- CONTEXTMENU STYLE -->
<Style x:Key="ContextMenu" TargetType="ContextMenu">
    <Setter Property="Background" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"/>
</Style>

<!-- MENU ITEM STYLE -->
<Style x:Key="MenuItem" TargetType="MenuItem">
    <Setter Property="Background" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"/>
</Style>

<StackPanel.ContextMenu>
    <ContextMenu Style="{StaticResource ContextMenu}">
        <MenuItem Header="Delete Gist" Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
                  Style="{StaticResource MenuItem}">
            <MenuItem.Icon>
                <imaging:CrispImage Moniker="{x:Static catalog:KnownMonikers.DeleteListItem}"/>
            </MenuItem.Icon>
        </MenuItem>
    </ContextMenu>
</StackPanel.ContextMenu>

The details of templates etc baffles me a bit. Any suggestions?
image.png
Was this page helpful?