WPF 菜单项边框
我在尝试实现 Menu
时遇到了问题,并且无法弄清楚发生了什么。我正在尝试使用 Menu
控件制作单层菜单。这是我的菜单代码:
<Menu DockPanel.Dock="Top" Height="22" Name="menu1" VerticalAlignment="Top" Background="#FF325170">
<MenuItem Header="Featured" Style="{StaticResource menuItemStyle}" />
<MenuItem Header="Search" Style="{StaticResource menuItemStyle}" />
</Menu>
我的 MenuItem
的样式如下:
<Style x:Key="menuItemStyle" TargetType="{x:Type MenuItem}">
<Style.Triggers>
<Trigger Property="MenuItem.IsMouseOver" Value="true">
<Setter Property = "Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
当我将鼠标悬停在菜单项上时,会出现一个 Border
,但我不能为我的一生弄清楚如何消除这个边界。有什么建议吗?
I've run into a problem trying to implement a Menu
and can't figure out what is going on. I'm trying to make a single-layer menu using the Menu
control. Here is my menu code:
<Menu DockPanel.Dock="Top" Height="22" Name="menu1" VerticalAlignment="Top" Background="#FF325170">
<MenuItem Header="Featured" Style="{StaticResource menuItemStyle}" />
<MenuItem Header="Search" Style="{StaticResource menuItemStyle}" />
</Menu>
And my style for my MenuItem
s is as follows:
<Style x:Key="menuItemStyle" TargetType="{x:Type MenuItem}">
<Style.Triggers>
<Trigger Property="MenuItem.IsMouseOver" Value="true">
<Setter Property = "Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
When I mouseover the menu items, there is a Border
that appears, and I can't figure out for the life of me how to remove this border. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于许多内置的 WPF 控件样式,您需要重写 ControlTemplate。
这里是提供菜单 ControlTemplate 的 MSDN 页面,其中包含有关如何使用它——基本上,您正在插入菜单控件所有样式的本地副本,然后覆盖默认控件的外观和感觉。
为了解决您的问题,您应该能够插入以下样式:
For a lot of the built-in WPF control styles, you need to override the ControlTemplate.
Here is the MSDN page that provides the Menu ControlTemplate, with instructions on how to use it -- basically you are inserting local copies of all the styles for the Menu control, which then override the default control look and feel.
To address your problem you should be able to just insert this style: