#139 – Dependency Property Value Sources: #5 – Style Triggers

The fifth source in the list of sources for the base value of a dependency property is a style trigger. A property obtains its value from a style trigger when a style is applied to the parent element and the property’s value changes as a result of a trigger firing.

In the example below, a button has the style blueTextButton applied to it.  This style sets the Foreground property to blue when you hover the mouse over the control.  The source of the Foreground property then becomes style trigger when the trigger fires.

    <Window.Resources>
        <Style x:Key="blueTextButton">
            <Style.Triggers>
                <Trigger Property="Button.IsMouseOver" Value="True">
                    <Setter Property="Button.Foreground" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel Orientation="Vertical">
        <Button Content="Run" Height="23" Width="75" Style="{StaticResource blueTextButton}" />
        <Button Content="Skip" Height="23" Width="75" />
    </StackPanel>
Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #139 – Dependency Property Value Sources: #5 – Style Triggers

  1. Pingback: #133 – Where a Dependency Property Gets Its Value « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: