using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace HKW.WPF.Converters;
public class BoolInverter : ValueConverterBase
{
///
///
///
public static readonly DependencyProperty NullValueProperty = DependencyProperty.Register(
nameof(NullValue),
typeof(bool),
typeof(BoolInverter),
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
)
{
if (value is not bool b)
return NullValue;
return !b;
}
}