Does anyone know how to change the brush for a menu’s background? This sounds simple, but I don’t see any obvious way to do this. You’d think that the Background property would change it, but it doesn’t.
Here’s what my menu looks like (notice the default white background):
Example Code:
<Window x:Class='WpfApplication1.Window1' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Title='Window1' Height='300' Width='300'> <Window.Resources> <SolidColorBrush x:Key='menuItemBrush' Color='#FF505050' /> </Window.Resources> <Grid x:Name='mainGrid' Background='#FF252525'> <Menu x:Name='mainMenu' Background='{DynamicResource menuItemBrush}' Grid.ColumnSpan='2' VerticalAlignment='Top'> <MenuItem x:Name='fileMenu' Background='{DynamicResource menuItemBrush}' Foreground='White' Header='File'> <MenuItem x:Name='fileOpenMenuItem' Background='{DynamicResource menuItemBrush}' Foreground='White' Header='Open...' /> <MenuItem x:Name='fileSaveMenuItem' Background='{DynamicResource menuItemBrush}' Foreground='White' Header='Save' /> <MenuItem x:Name='fileSaveAsMenuItem' Background='{DynamicResource menuItemBrush}' Foreground='White' Header='Save As...' /> <Separator Style='{DynamicResource menuItemSeperator}' /> <MenuItem x:Name='fileExitMenuItem' Background='{DynamicResource menuItemBrush}' Foreground='White' Header='Exit' /> </MenuItem> </Menu> </Grid>
I’d suggest using a tool called kaxaml for writing styles. It includes several code snippets, a color picker and a nice way to instantly see what changes in the xaml code does. Here is a full menu style for what you are trying to do. Just change the brush colors at the top to suit to your needs.