C# 如何删除上下文菜单突出显示效果?
我将以下关联菜单附加到一个矩形:C# 如何删除上下文菜单突出显示效果?,c#,wpf,xaml,mahapps.metro,C#,Wpf,Xaml,Mahapps.metro,我将以下关联菜单附加到一个矩形: <Rectangle x:Name="criteria1" IsHitTestVisible="True"> <Rectangle.ContextMenu> <ContextMenu> <Grid> <Grid.RowDefinitions> <RowDefinition Height=".5*"/&
<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>
这不就是你所需要的吗?
这不是你所需要的吗?你只需要在控件的样式模板中删除它,我在他们的文档中找不到它,但如果你将其提取并发布到这里,我相信有人会很快向你展示要删除的部分。或者只是看到了上下文菜单PopUp@ChrisW. 这不是模板吗?不,这是一个例子。我在您的问题中添加了默认的
ContextMenu
样式。请查看我的编辑。@jstreet因为他使用的是MahApps metro,所以它附带了自己的ContextMenu控件,我认为这是导致覆盖行为的原因,提供了所讨论的鼠标悬停效果。这将是此实例中所需的样式模板。CristianM请右键单击您的,选择编辑模板->编辑副本,并提供该副本。@ChrisW:我看到的唯一ContextMenu
来自System.Windows.Controls
命名空间。请指出Mahapps
名称空间中的位置,它自己的ContextMenu
。您只需要在控件的样式模板中删除它,我在他们的文档中找不到它,但如果您将其提取并发布到这里,我相信有人会很快向您展示要删除的部分。或者只是看到了上下文菜单PopUp@ChrisW. 这不是模板吗?不,这是一个例子。我在您的问题中添加了默认的ContextMenu
样式。请查看我的编辑。@jstreet因为他使用的是MahApps metro,所以它附带了自己的ContextMenu控件,我认为这是导致覆盖行为的原因,提供了所讨论的鼠标悬停效果。这将是此实例中所需的样式模板。CristianM请右键单击您的,选择编辑模板->编辑副本,并提供该副本。@ChrisW:我看到的唯一ContextMenu
来自System.Windows.Controls
命名空间。请指出Mahapps
名称空间中的位置它自己的ContextMenu
。将其设置为-Red而不是透明。整个上下文菜单都变红了吗?@CristianM等等,我刚刚又读了一遍你的问题。“鼠标悬停”是什么意思?上下文菜单不是仅通过右键单击显示吗?如果问题只在“悬停”期间出现,那么您应该向我们展示“悬停”之前的情况,以及您悬停的具体内容。将其设置为-Red而不是Transparent。整个上下文菜单都变红了吗?@CristianM等等,我刚刚又读了一遍你的问题。“鼠标悬停”是什么意思?上下文菜单不是仅通过右键单击显示吗?如果问题只在“悬停”期间出现,那么您应该向我们展示“悬停”之前的情况,以及您悬停的具体内容。
<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">