2011-11-23 69 views
1

我无法弄清楚如何将背景从无聊的灰色更改为其他东西。当我更改MenuItem的背景时,只会更改背景本身,而不会更改整个背景。是否有人知道如何设计它?如何风格的菜单项背景

这里是我当前菜单的图像:

enter image description here

我能做到这一点,但怎么样的边界?

enter image description here

回答

0

试试看:

<Style TargetType="{x:Type Menu}"> 
    <Setter Property="OverridesDefaultStyle" Value="True"/> 
    <Setter Property="Background" Value="Black" /> 
    <Setter Property="Foreground" Value="White" />  
</Style> 

<Style TargetType="{x:Type MenuItem}"> 
    <Setter Property="OverridesDefaultStyle" Value="True"/> 
    <Setter Property="Background" Value="Black" /> 
    <Setter Property="Foreground" Value="White" /> 
</Style> 

MSDN:Menu Styles and Templates

+0

当我这样做菜单都没有了。 – Sulby

+0

@ FireFly3000:你的意思是“全部走了”? – sll

+0

顺便说一句,你有没有设置OverridesDefaultStyle = true? – sll

0

<Menu Background="Gray" Height="23"> 
      <MenuItem Header="Menu1" Background="Green"> 
       <MenuItem Header="sub1" Background="Red"/> 
       <MenuItem Header="sub2" Background="Yellow"/> 
      </MenuItem> 
    </Menu> 

enter image description here

更新: 上面我的解决方案不会改变整个背景为您提到。 要有一个全新的风格阅读此:https://stackoverflow.com/q/519012/352101

+0

是的,但正如你所看到的那样,在我的情况是灰色的子菜单周围仍然有一个边框。 – Sulby