Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Trigger when property value is greater than a certain amount

Tags:

wpf

triggers

I want to do something like this:

<ControlTemplate.Triggers>     <Trigger Property="Width" Value=">25">        <!-- Set values here -->     </Trigger> </ControlTemplate.Triggers> 

Anyway to do something like this?

like image 957
Micah Avatar asked Jul 07 '09 19:07

Micah


1 Answers

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

Example:

   <Button Content="I change colour depending on my width for some reason">         <Button.Triggers>             <DataTrigger                 Binding="{Binding                 Path=Width,                 RelativeSource={RelativeSource Self},                 Converter={StaticResource isLessThanConverter},                 ConverterParameter=50}"                 Value="True">                 <Setter Property="Button.Background" Value="Red" />             <DataTrigger>         <Button.Triggers>     <Button> 

Reference

like image 77
Daniel Avatar answered Oct 06 '22 13:10

Daniel