tags:

views:

1162

answers:

4

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?

A: 

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

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

Steven Robbins
+1  A: 

Not without code behind. Usual practice 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.
Sergey Aldoukhov
I like the idea of using a converter even with bound data. When using the MVVM pattern it helps keep view code out of the viewmodel.
emddudley
+3  A: 

You need a custom converter. Take a look at article

Vasu Balakrishnan
A: 

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

Daniel