---
title: "How to override MenuItem Style of single role style"  
description: "How to override MenuItem Style of single role style"  
author: "Tom Cruser"  
published: 2014-11-04  
updated: 2014-11-04  
canonical: https://www.mindstick.com/forum/2509/how-to-override-menuitem-style-of-single-role-style  
category: "c#"  
tags: ["wpf", "wpf controls"]  
reading_time: 2 minutes  

---

# How to override MenuItem Style of single role style

is there any way to override a single [role](https://yourviews.mindstick.com/audio/1254/the-role-of-visualization-in-achieving-your-goals) [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) of [MenuItem](https://www.mindstick.com/forum/23048/menuitem-call-javascript-function)? I know the way to override the IsHighlighted [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) of MenuItem is to override the ContentTemplate. What i want is to override the ContentTemplate for Role "SubmenuItem"\

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

The {StaticResource SubmenuItemTemplateKey2} is my override ContentTemplate. For the other [roles](https://www.mindstick.com/articles/1366/membership-roles-user-profile-in-asp-dot-net) i want use the [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources) [templates](https://www.mindstick.com/articles/12874/crucial-benefits-of-using-powerpoint-templates-in-your-business-presentations) of MenuItem. Is there any way to do it?\

\

## Replies

### Reply by Anonymous User

You'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:

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

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.


---

Original Source: https://www.mindstick.com/forum/2509/how-to-override-menuitem-style-of-single-role-style

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
