0

I have the following in a Resource dictionary. The style is working but the trigger is not. Please help.

 <Style x:Key="MenuItemStyle" TargetType="{x:Type MenuItem}">
    <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
    <Setter Property="Background" Value="#FF181818" />
    <Setter Property="FontSize" Value="13.333" />
    <Setter Property="FontFamily" Value="Segoe UI" />
    <Setter Property="BorderThickness" Value="0" />

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="{StaticResource HighlightedBackgroundBrush}" />

         </Trigger>
    </Style.Triggers>


</Style>
Alan Floyd
  • 141
  • 1
  • 1
  • 6

1 Answers1

0

This is because the Background of the MenuItem is set by a Parent Template Trigger and by the rules of Dependency Property Value Precedence the value in the Template will be in force.

Related question on Stack Overflow: you have to override the control template of the MenuItem.

Community
  • 1
  • 1
Szabolcs Dézsi
  • 8,743
  • 21
  • 29
  • I'm new to WPF. Can You give an example of how to do that? – Alan Floyd Mar 04 '15 at 20:30
  • [Here](https://msdn.microsoft.com/en-us/library/ee230084(v=vs.110).aspx) is a description. Basically you have to add a `` to your Style there. I would use the default ControlTemplate of the MenuItem as a base. [Default Template related question](http://stackoverflow.com/questions/3548319/where-can-i-find-the-default-wpf-control-templates) I can't find the templates on MSDN.. – Szabolcs Dézsi Mar 04 '15 at 20:43
  • --- this make the menu vanish. – Alan Floyd Mar 05 '15 at 16:53