You could create an IValueConverter
, which converts an integer to a boolean based on the CutOff
. Then use DataTrigger.Value
of True
(or False
, depending on what you are returning).
WPF DataTrigger
s are strictly equality comparers if I remember correctly.
So something similar to:
public class CutoffConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return ((int)value) > Cutoff;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
public int Cutoff { get; set; }
}
Then use the following XAML.
<Window.Resources>
<myNamespace:CutoffConverter x:Key="AgeConverter" Cutoff="30" />
</Window.Resources>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Age,
Converter={StaticResource AgeConverter}}">
<DataTrigger.Value>true</DataTrigger.Value>
<Setter TargetName="Age" Property="Foreground" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…