0

Does anyone know how to remove that awful and annoying border that appears when you mouseover a menuitem in a menu.

I've messed around with styles and googled around but I can't wrap my head around it.

Example with a button in a menu;

enter image description here

4

1 回答 1

0

您可以在这篇 MSDN 文章MenuItem中找到该类的默认样式和控件模板。

显示让您烦恼的边框的控件是"Border"在属性触发器中命名其背景更改的控件IsHighlighted。这个边界是ControlTemplate用 key 定义的x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}"。移除触发器(以及为了完整起见边框)将使MenuItem您希望它出现。

这是原始控件模板:

<ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="MenuItem">
    <Border Name="Border">
        <Grid>
            <ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
        </Grid>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsHighlighted" Value="true">
            <Setter TargetName="Border" Property="Background" Value="{StaticResource NormalBrush}"/>
            <Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
    </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

这是调整后的模板:

<ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="MenuItem">
    <Grid>
        <ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
    </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
    </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
于 2013-04-26T14:03:38.057 回答