Kishore Kumar
Kishore Kumar

Reputation: 21863

When to use DataTrigger and when to use Converter?

Any Assumption or rule is there, when we can use DataTrigger and when we can use Converter?

Upvotes: 1

Views: 694

Answers (2)

Goblin
Goblin

Reputation: 8022

A DataTrigger can only be used to check for a specific value - it cannot e.g. check for ranges. A DataTrigger can be combined for multiple conditions (MultiTrigger) - a ValueConverter can only convert one value to another. (Of course, a MultiValueConverter can take many values (and listen for updates on all of them - but still only return one value.))

The two can be used in conjunction, though - say, having a ValueConverter that checks if the value is below 50 (returning true) to activate the DataTrigger (put it in the Binding of the DataTrigger).

So, there is no golden rule in my book - only circumstances that might make one of them unusable (or very, very hard to apply).

Upvotes: 1

Wouter Janssens
Wouter Janssens

Reputation: 1613

DataTriggers are used to change styling depending on a specific value. For example change the TextBlock to red when its content is a number below 0.

Converter is used to convert a value to another type of value. For example to convert a boolean to a Visibility enum value

Upvotes: 2

Related Questions