1.创建个转换器
public class ColorConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var isOK = value == null ? "" : value.ToString();
var fillColor = (isOK != "OK") ? System.Windows.Media.Brushes.Red
: System.Windows.Media.Brushes.Black;
return fillColor;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
2.界面添加引用
1)
<f:MControlBase
xmlns:convertor="clr-namespace:对应的转换器空间名"
<ResourceDictionary>
<convertor:ColorConvertor x:Key="ColorConvertor" />
</ResourceDictionary>
2)绑定值
Foreground="{Binding STATUS,Converter={StaticResource ResourceKey=ColorConvertor}}"