当鼠标位于菜单项(第一级)上方时,它会显示3D按钮效果。如何删除?
感谢。
修改:
尝试
<Style TargetType="MenuItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Transparent">
<Setter Property="BorderThickness" Value="0">
</Trigger>
</Style.Triggers>
</Style>
没有效果。
菜单XAML:
<Window x:Class="UCWPF.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:UCWPF.Converters"
Title="Window3" Height="600" Width="600"
Background="{StaticResource WindowBackgroundBrush}"
>
<StackPanel Style="{StaticResource WindowContainerStyle}">
<Menu>
<MenuItem Header="New" Icon="{StaticResource ImageNew}" />
<MenuItem Header="Open" Icon="{StaticResource ImageOpen}" />
<MenuItem Header="Save" Icon="{StaticResource ImageSave}" />
<MenuItem Header="Export" Icon="{StaticResource ImageExport}" />
</Menu>
...
这是截图: bordereffect http://img408.imageshack.us/img408/6517/menuborder.png
编辑2 :
强大的力量带来了很大的复杂性:(。
看起来整个菜单模板应该重新定义以实现我的目的。 3D效果由MenuItem子边框(用Snoop标识)给出,鼠标在鼠标悬停时将其BorderStyle设置为凸起。我不知道是否可以在<Style TargetType="MenuItem">
元素内触及该边框样式,我们将非常感谢任何反馈。
答案 0 :(得分:2)
<Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Style.Triggers>
<Trigger Property="Role" Value="TopLevelHeader">
<Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}"/>
<Setter Property="Grid.IsSharedSizeScope" Value="true"/>
</Trigger>
</Style.Triggers>
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
<Border Name="Border" >
<Grid>
<ContentPresenter
Margin="6,3,6,3"
ContentSource="Header"
RecognizesAccessKey="True" />
<Popup
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsSubmenuOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Fade">
<Border
Name="SubmenuBorder"
SnapsToDevicePixels="True"
Background="{DynamicResource NormalBrush}"
BorderBrush="{StaticResource SolidBorderBrush}"
BorderThickness="1" >
<ScrollViewer CanContentScroll="True"
Style="{StaticResource MenuScrollViewer}">
<StackPanel
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
</ScrollViewer>
</Border>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
<Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="Border" Property="Background" Value="{StaticResource NormalBrush}"/>
<Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/>
</Trigger>
<!--Snippettoplevelheader-->
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/>
<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/>
</Trigger>
<!--/Snippettoplevelheader-->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
触发器IsHighlighted定义鼠标结束时的样式,如果移除触发器,当鼠标移到顶部菜单上时不会显示任何内容
有关更多控件样式示例,请参阅http://msdn.microsoft.com/en-us/library/ms771597%28VS.85%29.aspx
答案 1 :(得分:1)
<MenuItem Header="Menu...">
<MenuItem Header="(none)"/>
<Separator/>
<MenuItem>
<MenuItem.Template>
<ControlTemplate>
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding .}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ControlTemplate>
</MenuItem.Template>
</MenuItem>
</MenuItem>