Crystal
Crystal

Reputation: 29518

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

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

Upvotes: 1

Views: 4188

Answers (1)

brunnerh
brunnerh

Reputation: 185553

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>

Upvotes: 4

Related Questions