<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?
Anonymous User
04-Nov-2014You're trying to override all the menu items and next trying to override it again (to set it back to default style). In this case you just need to override the menu item with role of SubmenuItem, so the code can be just like this:
Otherwise (following your original approach), we may need some dummy MenuItem element which has the default style. Then we can Bind the Template of whatever items to the Template of that dummy element to restore their default style.