/// <summary> /// 枚举转bool /// </summary> public class Enum2BooleanConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value == null ? false : value.Equals(parameter); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var res = value != null && value.Equals(true) ? parameter : Binding.DoNothing; return res; } }
使用示例:
<UserControl ..... xmlns:enum ="...."> <RadioButton IsChecked="{Binding Path=IsChecked,Mode=TwoWay,
Converter={StaticResource Enum2BooleanConverter},
ConverterParameter={x:Static enum:DefectLevel.LevelA}}">
标签:object,value,枚举,bool,wpf,parameter,public From: https://www.cnblogs.com/moon-stars/p/18099289