开发者

Styling Separator in WPF to match background

I have a background with a custom color for a ContextMenu. I added in a separator as so (between different menu items):

<S开发者_StackOverfloweparator Background="#EDECEC" Margin="0" ></Separator>

The background color is #edecec. However, I see a separator, and the color doesn't match the rest of the contextmenu. It is lighter than the contextmenu. Is there a way to change that? Thanks.


The Separator in menus has a default Template which ignores the Background, to override it add a respective style to some ancestor's Resources using the right key:

<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}"
       TargetType="{x:Type Separator}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Separator}">
                <!-- ControlTemplate with a TemplateBinding to Background here -->
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜