tags:

views:

256

answers:

1

I try to understand the advantage of Properties Triggers over Data Triggers in WPF. It seems that Properties Triggers can be triggered only by a value that changed in dependency property, and Data Triggers can be triggered both by a value that changed in dependency property, and a value that changed in a .Net object that implement INotifyPropertyChange. So my question is, why not always use Data Triggers?

+3  A: 

Trigger looks at properties in the item you're styling/templating, whereas DataTrigger looks at the current DataContext by default.

Example:

<Style TargetType="ListBoxItem">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <!-- applied when mouse is over the ListBoxItem -->
        </Trigger>
        <DataTrigger Binding="{Binding Name}" Value="Kent">
            <!-- applied when the ListBoxItem's data has a Name property set to "Kent" -->
        </DataTrigger>
    </Style.Triggers>
</Style>

HTH, Kent

Kent Boogaart
So the only property trigger advantage is, that it's a shorter way to get triggered by a value change in the styled item property? since I can bind to the styled item properties using DataTrigger...
Andy
I highly suspect it's more efficient, too.
Kent Boogaart