huzige0265

导航

< 2025年1月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8
 

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}}"

 

posted on   huzige0265  阅读(141)  评论(0编辑  收藏  举报
 
点击右上角即可分享
微信分享提示