WPF 上的样式菜单项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14464871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Styled MenuItem on WPF
提问by Sonhja
I'm developing a menu on WPF. I have this menu til now:
我正在 WPF 上开发菜单。我现在有这个菜单:


When the menu is hovered, it looks like UsersmenuItem. This is the code behind:
当菜单悬停时,它看起来像UsersmenuItem。这是后面的代码:
<Menu Grid.Column="0" Name="menuNavigation" >
<MenuItem Header="Users" >
<MenuItem Header="Register user">
<MenuItem ToolTip="Register new user on database." />
</MenuItem>
<MenuItem Header="Admin users">
<MenuItem ToolTip="Update or delete a user." />
</MenuItem>
</MenuItem>
<MenuItem Header="Identify">
<MenuItem ToolTip="Start an identification." />
</MenuItem>
<MenuItem Header="Authenticate">
<MenuItem ToolTip="Start an authentication." />
</MenuItem>
<MenuItem Header="Cameras">
<MenuItem ToolTip="Manage connected cameras." />
</MenuItem>
</Menu>
I want that light blue border to disappear, and I was trying to simulate a special effect. When I hover it, I want a kind of white parenthesis surrounding the word, like emphasizing it.
我希望淡蓝色边框消失,我试图模拟一种特殊效果。当我悬停它时,我希望在这个词周围有一个白色的括号,就像强调它一样。
Can anybody give me an idea on how to start with this?
任何人都可以给我一个关于如何开始的想法吗?
EDIT:I could access the IsMouseOverevent, but it seems to ignore me. I have this styling now:
编辑:我可以访问该IsMouseOver事件,但它似乎忽略了我。我现在有这个样式:
<!-- Menu navigation properties -->
<Style TargetType="Menu">
<Setter Property="Background" Value="{DynamicResource TopMenuGradient}" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="Calibri" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Height" Value="50" />
</Style>
<!-- MenuItem Style -->
<Style TargetType="MenuItem">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Height" Value="50" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True" >
<Setter Property="Foreground" Value="LightGray" />
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
I could remove the light blue border, but I want to change the Backgroundproperty, but the MenuItemstyle seems to ignore me... partly. I mean: Foregroundworks... but not the Background! What's wrong?
我可以删除浅蓝色边框,但我想更改Background属性,但MenuItem样式似乎忽略了我......部分。我的意思是:Foreground有效......但不是Background!怎么了?

