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}}"
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步