using System.ComponentModel; using System.Globalization; using System.Windows; namespace HKW.WPF.Converters; /// /// 是布尔值转换器 /// public class IsBoolConverter : ValueConverterBase { /// /// /// public static readonly DependencyProperty BoolValueProperty = DependencyProperty.Register( nameof(BoolValue), typeof(bool), typeof(AllIsBoolToVisibilityConverter), new PropertyMetadata(true) ); /// /// 目标布尔值 /// [DefaultValue(true)] public bool BoolValue { get => (bool)GetValue(BoolValueProperty); set => SetValue(BoolValueProperty, value); } /// /// /// public static readonly DependencyProperty NullValueProperty = DependencyProperty.Register( nameof(NullValue), typeof(bool), typeof(AllIsBoolToVisibilityConverter), new PropertyMetadata(false) ); /// /// 为空值时布尔值 /// [DefaultValue(false)] public bool NullValue { get => (bool)GetValue(NullValueProperty); set => SetValue(NullValueProperty, value); } /// public override object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { return HKWUtils.HKWUtils.GetBool(value, BoolValue, NullValue); } }