簡體   English   中英

如何刪除ContextMenu高亮效果?

[英]How to remove ContextMenu highlight effect?

我將以下上下文菜單附加到矩形:

<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>

在鼠標懸停時,我得到這種突出顯示效果,背景變為深灰色:

在此輸入圖像描述

如何刪除此突出顯示效果?

UPDATE

只有通過右鍵單擊才會顯示上下文菜單。 設置ContextMenu Background="Red"Grid Background="Red" ,菜單如下所示:

在此輸入圖像描述

當鼠標進入或進入菜單內部或者即使我在文本框內單擊時,它看起來像這樣:

在此輸入圖像描述

編輯:這是默認的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>
<ContextMenu Background="Transparent">

這不就是你需要的嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM