Share via


How to: Use Triggers to Style a ContextMenu Item

This example shows how to use Trigger elements to style a MenuItem in a ContextMenu.

A Style is created that changes the appearance of a MenuItem in response to events that are raised on the item. When you move the mouse over the item, the foreground color and font characteristics change.

Example

<Style x:Key="Triggers" TargetType="{x:Type MenuItem}">
    <Style.Triggers>
    <Trigger Property="MenuItem.IsMouseOver" Value="true">
        <Setter Property = "FontSize" Value="16"/>
        <Setter Property = "FontStyle" Value="Italic"/>
    <Setter Property = "Foreground" Value="Red"/>
    </Trigger>
    </Style.Triggers>
</Style>

For the complete sample, see ContextMenu Styles Sample.

See Also

Tasks

How to: Create a ContextMenu

Reference

ContextMenu
Menu
MenuItem

Concepts

ContextMenu Overview