问题描述
我正在 WPF 上开发菜单.我现在有这个菜单:
I'm developing a menu on WPF. I have this menu til now:
当菜单悬停时,它看起来像 Users
menuItem.这是后面的代码:
When the menu is hovered, it looks like Users
menuItem. This is the code behind:
<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?
我可以访问 IsMouseOver
事件,但它似乎忽略了我.我现在有这种样式:
I could access the IsMouseOver
event, but it seems to ignore me. I have this styling now:
<!-- 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>
我可以移除浅蓝色边框,但我想更改 Background
属性,但是 MenuItem
样式似乎忽略了我......部分.我的意思是:Foreground
有效......但不是 Background
!怎么了?
I could remove the light blue border, but I want to change the Background
property, but the MenuItem
style seems to ignore me... partly. I mean: Foreground
works... but not the Background
! What's wrong?
推荐答案
这很有帮助 link 来自 codeproject.关于悬停,WPF 网格控件同时支持 MouseEnter 和 MouseLeave 事件.您应该能够为两者连接事件处理程序.
this is s helpful link from codeproject. Regarding the hover, a WPF Grid control supports both the MouseEnter and MouseLeave events. You should be able to hook up event handlers for both.
另请参阅this一个>
这篇关于WPF 上的样式菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!