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.


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">
    <Trigger Property="IsMouseOver" Value="true">
        <Setter Property = "Background" Value="Red"/>
    <Trigger Property="IsPressed" Value="true">
        <Setter Property = "Foreground" Value="Green"/>

For the complete sample, see Button Styles Sample.

See Also