This documentation is archived and is not being maintained.

How to: Use Triggers to Style a Button

.NET Framework 3.0

This example shows how to use Trigger elements to style a Button control.

Example

The following example creates a style that changes the appearance of a Button in response to events that are raised on the control. When you move the mouse pointer over the Button, the Background color changes and if you click the Button, the Foreground color changes.

<Style x:Key="Triggers" TargetType="Button">
    <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="true">
        <Setter Property = "Background" Value="Red"/>
    </Trigger>
    <Trigger Property="IsPressed" Value="true">
        <Setter Property = "Foreground" Value="Green"/>
    </Trigger>
    </Style.Triggers>
</Style>

For the complete sample, see Button Styles Sample.

See Also

Show: