Sergio Tapia
Sergio Tapia

Reputation: 41138

When setting the background color of a Menu, the colors only appears on the top most level

All of the MenuItems do not inherit the color. Is there a way in WPF for me to set the color automatically from the main parent colors? Thanks.

I've just discovered that the Foreground property goes through all children. Background doesn't though. :(

Upvotes: 0

Views: 219

Answers (1)

Drew Marsh
Drew Marsh

Reputation: 33379

This is happening because of the default style/template of a ContextMenu. You need to change the template of the MenuItems in your Menu to achieve the results you desire. You can do this by defining a Style with Key="{x:Type MenuItem}" in the Menu.Resources:

<Menu>
    <Menu.Resources>
        <Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
            <Style Property="Template">
                <Style.Value>
                    <ControlTemplate TargetType="{x:Type MenuItem}">
                       <!-- your template parts here using -->
                    </ControlTemplate>
                </Style.Value>
            </Style>
        </Style>
    </Menu.Resources>
</Menu>

Upvotes: 1

Related Questions