Here is the default ControlTemplate of ContextMenu in https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/contextmenu-styles-and-templates?view=netframeworkdesktop-4.8&viewFallbackFrom=netdesktop-6.0
I change it like this:
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="SnapsToDevicePixels"
Value="True" />
<Setter Property="Grid.IsSharedSizeScope"
Value="true" />
<Setter Property="HasDropShadow"
Value="True" />
<Setter Property="Background" Value="White"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border x:Name="Border" Margin="10" Background="{TemplateBinding Background}"
BorderThickness="0" BorderBrush="{Binding BorderBrush}" CornerRadius="2">
<Border.Effect>
<DropShadowEffect Color="Gray" BlurRadius="10" Direction="-90" Opacity="0.3"
RenderingBias="Quality" ShadowDepth="2" />
</Border.Effect>
<StackPanel IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Now I met a problem, when I hover into the item, even if it is a TextBlock like this:
<Grid.ContextMenu>
<ContextMenu>
<TextBlock>123</TextBlock>
</ContextMenu>
</Grid.ContextMenu>
It always changes its background to blue as the image above.
What's wrong with it? I want to change the background to my favorite color while I hover it. How can I achieve this?
