Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 2.85 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. The trigger dosn't work when value is corrent
  2. <Label x:Name="label" Content="{Binding Text, ElementName=textBox2}"HorizontalAlignment="Left" Margin="69,110,0,0" Width="122.63" VerticalAlignment="Top"Background="White"FontSize="26.667">
  3.        
  4. <Style TargetType="Label">
  5.                 <Style.Triggers>
  6.                     <DataTrigger Binding="{Binding Label.Content, Converter={StaticResource dc}}"   Value="Above24">
  7.                         <Setter  Property="Foreground">
  8.                             <Setter.Value>
  9.                                 <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  10.                                     <GradientStop Color="Black" Offset="1"/>
  11.                                     <GradientStop Color="#FFCE0A0A"/>
  12.                                     <GradientStop Color="#FF2A0202" Offset="0.75"/>
  13.                                     <GradientStop Color="#FF5B0404" Offset="0.5"/>
  14.                                     <GradientStop Color="#FF9C0707" Offset="0.25"/>
  15.                                 </LinearGradientBrush>
  16.                             </Setter.Value>
  17.                         </Setter>
  18.                     </DataTrigger>
  19.                 </Style.Triggers>
  20.             </Style>
  21.         </Label.Style>
  22.     </Label>
  23.        
  24. class
  25. DataConverter
  26. :
  27. IValueConverter
  28. {
  29.         object IValueConverter.Convert
  30. (object value,
  31. Type targetType,
  32.  object parameter,
  33. System.Globalization.CultureInfo culture)
  34. {
  35.             if (value == null) return false;
  36.             if (string.IsNullOrEmpty(value.ToString())) return false;
  37.             if (Convert.ToInt32(value) < 18) return "Below18";
  38.             if (Convert.ToInt32(value) > 24) return "Above24";
  39.             return Convert.ToInt32(value) < 100;
  40.         }
  41.     object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  42.     {
  43.         return null;
  44.     }
  45. }
  46.        
  47. <Style TargetType="Label">
  48.             <Style.Triggers>
  49.                 <DataTrigger Binding="{Binding Content, RelativeSource={RelativeSource Self},Converter={StaticResource dc}}"   Value="Above24">
  50.                     <Setter  Property="Foreground">
  51.                         <Setter.Value>
  52.                             <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  53.                                 <GradientStop Color="Black" Offset="1"/>
  54.                                 <GradientStop Color="#FFCE0A0A"/>
  55.                                 <GradientStop Color="#FF2A0202" Offset="0.75"/>
  56.                                 <GradientStop Color="#FF5B0404" Offset="0.5"/>
  57.                                 <GradientStop Color="#FF9C0707" Offset="0.25"/>
  58.                             </LinearGradientBrush>
  59.                         </Setter.Value>
  60.                     </Setter>
  61.                 </DataTrigger>
  62.             </Style.Triggers>
  63.         </Style>
  64.     </Label.Style>
  65. </Label>