[ACCEPTED]-WPF Trigger when property value is greater than a certain amount-triggers

Accepted answer
Score: 38

You can use a data trigger and set the binding 2 RelativeSource to Self. Data Triggers allow 1 binding and bindings lets you have converters.


   <Button Content="I change colour depending on my width for some reason">
                RelativeSource={RelativeSource Self},
                Converter={StaticResource isLessThanConverter},
                <Setter Property="Button.Background" Value="Red" />


Score: 6

Not without code behind. Usual practice 1 is:

  • When working with UI elements, create an IValueConverter and bind to the property using the converter.
  • When working with bound data, create a bool property on your data and trigger from that property.
Score: 2

Something might have been added in SP1, but 6 the way I've achieved this in the past is 5 with a ValueConvertor that converts the 4 value into a boolean.

In your example your 3 convertor would return true if the value 2 was > 25, false otherwise. If that doesn't 1 make sense I can put an example up :-)

Score: 0

Data Trigger only validates exact value, not 3 validates "evaluated values"(like greater 2 than, less than, addition etc.). you need 1 a converter to convert to exact value.

More Related questions