2023-12-30 15:50:37 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace HKW.WPF.Converters;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是布尔值转换器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class IsBoolConverter : ValueConverterBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly DependencyProperty BoolValueProperty = DependencyProperty.Register(
|
|
|
|
|
nameof(BoolValue),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(AllIsBoolToVisibilityConverter),
|
|
|
|
|
new PropertyMetadata(true)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 目标布尔值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(true)]
|
|
|
|
|
public bool BoolValue
|
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(BoolValueProperty);
|
|
|
|
|
set => SetValue(BoolValueProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly DependencyProperty NullValueProperty = DependencyProperty.Register(
|
|
|
|
|
nameof(NullValue),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(AllIsBoolToVisibilityConverter),
|
|
|
|
|
new PropertyMetadata(false)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为空值时布尔值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool NullValue
|
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(NullValueProperty);
|
|
|
|
|
set => SetValue(NullValueProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override object Convert(
|
|
|
|
|
object value,
|
|
|
|
|
Type targetType,
|
|
|
|
|
object parameter,
|
|
|
|
|
CultureInfo culture
|
|
|
|
|
)
|
|
|
|
|
{
|
2024-02-04 09:37:45 +00:00
|
|
|
|
return HKWUtils.HKWUtils.GetBool(value, BoolValue, NullValue);
|
2023-12-30 15:50:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|