如何删除ContextMenu高亮效果?

时间:2016-06-23 19:34:06

标签: c# wpf xaml mahapps.metro

我将以下上下文菜单附加到矩形:

<Rectangle x:Name="criteria1" IsHitTestVisible="True">
 <Rectangle.ContextMenu>
    <ContextMenu>
        <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height=".5*"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width=".5*"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Grid.Row="0" Content="Amplitude percentage"/>
                <TextBox Grid.Column="1" Grid.Row="0" mah:TextBoxHelper.ClearTextButton="True" mah:ControlsHelper.FocusBorderBrush="{DynamicResource AccentColorBrush}" Width="70" >
                    <TextBox.Text>
                        <Binding Path="Criteria1AmplitudePercentage" TargetNullValue="{x:Static sys:String.Empty}" UpdateSourceTrigger="LostFocus" ValidatesOnDataErrors="True" />
                    </TextBox.Text>
                </TextBox>
                <Label Grid.Column="0" Grid.Row="1" Content="Bandwidth percentage}" />
                <TextBox Grid.Column="1" Grid.Row="1" mah:TextBoxHelper.ClearTextButton="True" mah:ControlsHelper.FocusBorderBrush="{DynamicResource AccentColorBrush}" Width="70" >
                    <TextBox.Text>
                        <Binding Path="Criteria1BandwidthPercentage" TargetNullValue="{x:Static sys:String.Empty}" UpdateSourceTrigger="LostFocus" ValidatesOnDataErrors="True" />
                    </TextBox.Text>
                </TextBox>
            </Grid>
    </ContextMenu>
</Rectangle.ContextMenu>

鼠标悬停时,我会得到这种突出显示效果,背景变为深灰色:

enter image description here

如何删除此突出显示效果?

更新

只有通过右键单击才会显示上下文菜单。设置ContextMenu Background="Red"Grid Background="Red"时,菜单如下所示:

enter image description here

当鼠标进入或进入菜单内部或者即使我在文本框内单击时,它看起来像这样:

enter image description here

编辑:这是默认的ContextMenu样式:

        <Style x:Key="ContextMenuDefaultStyle" TargetType="{x:Type ContextMenu}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Background" Value="{DynamicResource MenuPopupBackgroundBrush}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="{DynamicResource MenuPopupBorderBrush}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="2"/>
        <Setter Property="Grid.IsSharedSizeScope" Value="True"/>
        <Setter Property="HasDropShadow" Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
        <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MessageFontFamilyKey}}"/>
        <Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MessageFontSizeKey}}"/>
        <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MessageFontWeightKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <Border Uid="Border_93">
                        <Border.Style>
                            <Style TargetType="{x:Type Border}">
                                <Setter Property="Tag" Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Tag, RelativeSource={RelativeSource Self}}" Value="True">
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Setter Property="Padding" Value="0,0,5,5"/>
                                        <Setter Property="Effect">
                                            <Setter.Value>
                                                <DropShadowEffect BlurRadius="4" Opacity="0.8" ShadowDepth="1"/>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Border.Style>
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Uid="Border_50">
                            <ScrollViewer CanContentScroll="True" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" Uid="ScrollViewer_9">
                                <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Uid="ItemsPresenter_5"/>
                            </ScrollViewer>
                        </Border>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

1 个答案:

答案 0 :(得分:0)

<ContextMenu Background="Transparent">

这不是你所需要的全部吗?