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
2009-04-28 10:40:33
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
2009-04-28 10:57:00
I highly suspect it's more efficient, too.
Kent Boogaart
2009-04-28 10:58:18