I am using MetroDark theme to skin my WPF application, which unfortunately doesn't have MenuItem. So I want to change Foreground and Background for four states of menu item:
- normal
- hovered
- pressed
- disabled
So far I have code like this, and what it does is just set Foreground and Background when mouse hovering the menu item:
<Menu Background="#FF181818" Foreground="#FFABABAB" >
<Menu.Resources>
<Style x:Key="{x:Type MenuItem}" >
<Style.Setters>
<Setter Property="MenuItem.Background" Value="#FF181818" />
<Setter Property="MenuItem.Foreground" Value="#FFABABAB" />
</Style.Setters>
<Style.Triggers>
<Trigger Property="MenuItem.IsMouseOver" Value="True">
<Setter Property="MenuItem.Background" Value="Green" />
<Setter Property="MenuItem.Foreground" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Menu.Resources>
<MenuItem Header="File">
<MenuItem Header="New" Command="ApplicationCommands.New"></MenuItem>
<MenuItem Header="Open" Command="ApplicationCommands.Open"></MenuItem>
<MenuItem Header="Save" Command="ApplicationCommands.Save"></MenuItem>
<MenuItem Header="Save As" Command="ApplicationCommands.SaveAs"></MenuItem>
<Separator Background="#FF181818" Foreground="#FFABABAB"></Separator>
<MenuItem Header="Delete" Command="ApplicationCommands.Delete"></MenuItem>
<MenuItem Header="Quit" Click="Quit_MenuItem_Click"></MenuItem>
</MenuItem>
<MenuItem Header="Format" Click="Format_MenuItem_Click" ></MenuItem>
<MenuItem Header="About" ></MenuItem>
</Menu>
The result is: The setting of Foreground works, however, that for Background only works for the MenuItem which are immediate children of Menu, not whose sub-menu items.
I have noticed this Styled MenuItem on WPF , which may be relevant. But my question is can I fix this without ControlTemplate? And I am looking for a solution can be applied for all the other states, like IsDisabled and IsPressed.
Thanks so much!