Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF如何设置关联菜单的背景色,使其覆盖网格的背景色_Wpf - Fatal编程技术网

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>