© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
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>
<!-- 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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ c# wpf change background color of whitespace character
C#CC# / help
3y ago
[WPF] DragDrop problems
C#CC# / help
2y ago
Background color of .net
C#CC# / help
2y ago
button background not changing wpf
C#CC# / help
2y ago