WPF如何设置关联菜单的背景色,使其覆盖网格的背景色
我有一套风格如下:WPF如何设置关联菜单的背景色,使其覆盖网格的背景色,wpf,Wpf,我有一套风格如下: <Style TargetType="Grid" > <Setter Property="Control.Background"> <Setter.Value> <SolidColorBrush> <SolidColorBrush.Color> <Col
<Style TargetType="Grid" >
<Setter Property="Control.Background">
<Setter.Value>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="255" R="51" G="50" B="51"/>
</SolidColorBrush.Color>
</SolidColorBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="contextMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}" >
<Setter Property="Background" Value="Pink" />
</Style>
然后,我为上下文菜单设置了如下样式:
<Style x:Key="contextMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}" >
<Setter Property="Background" Value="Pink" />
</Style>
关联菜单出现在嵌套在网格中的StackPanel上。我不明白为什么,但是上下文菜单的背景总是用粉色勾勒出来的黑色。使关联菜单正确显示的唯一方法是禁用网格的样式。我已经尝试了我能想到的一切,包括为ContextMenu创建一个ControlTemplate
<Style x:Key="contextMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}" >
<Setter Property="Background" Value="Pink" />
</Style>
为什么网格背景色会影响菜单背景色?我到底该如何让它停止呢?
<Style x:Key="contextMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}" >
<Setter Property="Background" Value="Pink" />
</Style>
<Style TargetType="Grid" >
并使用Style={StaticResource myGridStyle}为您希望使用此特定颜色的网格设置样式。先生,您是一位学者和绅士。我没有意识到它在默认情况下在上下文菜单中呈现了一个网格,也没有意识到该样式向下推进了多远。
<Style x:Key="contextMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}" >
<Setter Property="Background" Value="Pink" />
</Style>