views:

233

answers:

1

I would like to apply a style, to a ProgressBar, for when it between certain values the style should change.

<Style x:Key="ProBar" TargetType="{x:Type ProgressBar}">    
      <Style.Triggers>
        <Trigger Property="Value" Value="<10">
          <Setter Property="Foreground">
            <Setter.Value>
              <!--OrangeColour-->
              <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFFFFFFF" Offset="0" />
                <GradientStop Color="#FFFDDF97" Offset="0.992" />
                <GradientStop Color="#FFF7DCAB" Offset="0.02" />
                <GradientStop Color="#FFFFDC9E" Offset="0.5" />
                <GradientStop Color="#FFFDA564" Offset="0.513" />
              </LinearGradientBrush>
            </Setter.Value>
          </Setter>
        </Trigger>      
      </Style.Triggers>
    </Style>

Is it possible to do this in any way?

+2  A: 

Use a DataTrigger, a Binding and a IValueConverter

<DataTrigger Binding="{Binding Value, Converter={StaticResource IsMyValueLowEnoughConverter}}" Value="True">

Converter:

public class IsMyValueLowEnoughConverter : IValueConverter
{
    public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return ((int)value) < 10;
    }

    public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new System.NotImplementedException();
    }
}

Be sure to put the converter in your resources of your original xaml file:

<IsMyValueLowEnoughConverter x:Key="IsMyValueLowEnoughConverter" />
Arcturus