MouseOver 使用覆盖的 ControlTemplate 在 ContextMenu 上触发触发。它从哪里来?
我有这个非常简单的 ControlTemplate:
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border
Name="Border"
Background="{StaticResource BlueBackground}"
BorderBrush="LightBlue"
CornerRadius="10"
BorderThickness="1" >
<StackPanel IsItemsHost="True"/>
</Border>
</ControlTemplate>
我用它来创建一个漂亮得令人瞠目结舌的美丽圆角!然而,当我将鼠标指向上下文菜单时,鼠标悬停触发器会从某处触发,在我漂亮的圆形边框顶部绘制一个非常难看的近乎方形的边框!
它从哪里来?
编辑: 最可能的原因是 ContextMenu 是一个包含 MenuItems 的 ItemsControl,即使我的 ContextMenu 包含单个 UserControl。因此,当 IsMouseOver==true 时,UserControl 被视为 MenuItem 并突出显示!禁用此行为的最简单方法是什么?
I have this very simple ControlTemplate:
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border
Name="Border"
Background="{StaticResource BlueBackground}"
BorderBrush="LightBlue"
CornerRadius="10"
BorderThickness="1" >
<StackPanel IsItemsHost="True"/>
</Border>
</ControlTemplate>
I made it to create a nifty jawdroppingly beautiful rounded corner! However, when I point the mouse over a contextmenu a MouseOver Trigger fires from somewhere that draws a terribly ugly nearly square border on top of my nifty rounded border!
Where is it coming from??
EDIT:
The most likely cause is that the ContextMenu is an ItemsControl that holds MenuItems, even when my ContextMenu holds a single UserControl. So the UserControl is seen as a MenuItem and highlighted when the IsMouseOver==true! What is the easiest way to disable this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 ContextMenu 的 ItemContainerStyle 属性设置为 MenuItems 的自定义样式。
使用此策略,您必须为您想要的任何鼠标悬停效果创建自己的触发器,但 Click 和 Checked 事件仍将正常触发。
You can set the ItemContainerStyle property of your ContextMenu to a custom style for MenuItems.
With this strategy you have to make your own triggers for any mouse over effects you want, but Click and Checked events will still fire normally.