2023-12-30 15:50:37 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Windows;
|
2023-12-24 16:31:22 +00:00
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
2023-12-30 15:50:37 +00:00
|
|
|
|
namespace HKW.WPF.Converters;
|
2023-12-24 16:31:22 +00:00
|
|
|
|
|
2023-12-30 15:50:37 +00:00
|
|
|
|
public class BoolInverter : ValueConverterBase
|
2023-12-24 16:31:22 +00:00
|
|
|
|
{
|
2023-12-30 15:50:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly DependencyProperty NullValueProperty = DependencyProperty.Register(
|
|
|
|
|
nameof(NullValue),
|
|
|
|
|
typeof(bool),
|
2024-01-15 20:46:14 +00:00
|
|
|
|
typeof(BoolInverter),
|
2023-12-30 15:50:37 +00:00
|
|
|
|
new PropertyMetadata(false)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为空值时布尔值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool NullValue
|
2023-12-24 16:31:22 +00:00
|
|
|
|
{
|
2023-12-30 15:50:37 +00:00
|
|
|
|
get => (bool)GetValue(NullValueProperty);
|
|
|
|
|
set => SetValue(NullValueProperty, value);
|
2023-12-24 16:31:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 15:50:37 +00:00
|
|
|
|
public override object Convert(
|
|
|
|
|
object value,
|
|
|
|
|
Type targetType,
|
|
|
|
|
object parameter,
|
|
|
|
|
CultureInfo culture
|
|
|
|
|
)
|
2023-12-24 16:31:22 +00:00
|
|
|
|
{
|
2023-12-30 15:50:37 +00:00
|
|
|
|
if (value is not bool b)
|
|
|
|
|
return NullValue;
|
|
|
|
|
return !b;
|
2023-12-24 16:31:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|