forum

Home / DeveloperSection / Forums / How to override MenuItem Style of single role style

How to override MenuItem Style of single role style

Tom Cruser258204-Nov-2014
is there any way to override a single role style of MenuItem? I know the way to override the IsHighlighted color of MenuItem is to override the ContentTemplate. What i want is to override the ContentTemplate for Role "SubmenuItem"

<Stylex:Key="ActionMenuItemStyle"TargetType="{x:Type MenuItem}">
    <SetterProperty="HorizontalContentAlignment"Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <SetterProperty="VerticalContentAlignment"Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <SetterProperty="Background"Value="Transparent"/>
    <SetterProperty="Template"Value="{StaticResource SubmenuItemTemplateKey2}"/>
    <SetterProperty="Foreground"Value="Black"/>
    <Style.Triggers>
        <TriggerProperty="Role"Value="TopLevelHeader">
            <SetterProperty="Padding"Value="7,2,8,3"/>
            <SetterProperty="Template"Value="???"/>
            <SetterProperty="Foreground"Value="White"/>
        </Trigger>
        <TriggerProperty="Role"Value="TopLevelItem">
            <SetterProperty="Padding"Value="7,2,8,3"/>
            <SetterProperty="Template"Value="???"/>
        </Trigger>
        <TriggerProperty="Role"Value="SubmenuHeader">
            <SetterProperty="Padding"Value="2,3,2,3"/>
            <SetterProperty="Template"Value="???"/>
        </Trigger>
        <TriggerProperty="Role"Value="SubmenuItem">
            <SetterProperty="Padding"Value="2,3,2,3"/>
        </Trigger>
    </Style.Triggers>
</Style>

The {StaticResource SubmenuItemTemplateKey2} is my override ContentTemplate. For the other roles i want use the default templates of MenuItem. Is there any way to do it?



Updated on 04-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By