[ACCEPTED]-What's the difference between a Trigger and a DataTrigger?-datatrigger
A regular Trigger
only responds to dependency properties.
A 3 DataTrigger
can be triggered by any .NET property (by 2 setting its Binding
property). However, its setters 1 can still target only dependency properties.
Another difference is that a DataTrigger
can be bound 8 to another control, a StaticResource, etc 7 etc.
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger
Binding="{Binding SomeProperty,
ElementName=someOtherControl"
Value="Derp">
<!-- etc -->
You can only examine the instance on 6 which the style is set when using a Trigger
. For 5 example, a Trigger
applied to a Button can inspect 4 the value of IsPressed
, but it would not be able 3 to inspect the (for example) Text
value of a 2 TextBox
on the same form if you wished to disable 1 the Button
if the TextBox
was empty.
The short answer (as I'm about to sleep)- A 4 trigger works on dependency properties (typically GUI properties) whereas 3 data triggers can be triggered by any .NET 2 property (typically a property in a ViewModel 1 that implements INotifyPropertyChanged).
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.