using System.ComponentModel;
using System.Globalization;
using System.Windows;
namespace HKW.WPF.Converters;
///
/// 全部为布尔值转换器
///
public class AllIsBoolToVisibilityConverter
: MultiValueToBoolConverter
{
///
///
///
public static readonly DependencyProperty BoolOnNullProperty = DependencyProperty.Register(
nameof(BoolOnNull),
typeof(bool),
typeof(AllIsBoolToVisibilityConverter),
new PropertyMetadata(false)
);
///
/// 目标为空时的指定值
///
[DefaultValue(false)]
public bool BoolOnNull
{
get => (bool)GetValue(BoolOnNullProperty);
set => SetValue(BoolOnNullProperty, value);
}
///
///
///
public static readonly DependencyProperty VisibilityOnTrueProperty =
DependencyProperty.Register(
nameof(VisibilityOnTrue),
typeof(Visibility),
typeof(AllIsBoolToVisibilityConverter),
new PropertyMetadata(Visibility.Visible)
);
///
/// 目标为空时的指定值
///
[DefaultValue(Visibility.Visible)]
public Visibility VisibilityOnTrue
{
get => (Visibility)GetValue(TargetBoolValueProperty);
set => SetValue(TargetBoolValueProperty, value);
}
///
///
///
public static readonly DependencyProperty VisibilityOnFalseProperty =
DependencyProperty.Register(
nameof(VisibilityOnFalse),
typeof(Visibility),
typeof(AllIsBoolToVisibilityConverter),
new PropertyMetadata(Visibility.Hidden)
);
///
/// 目标为空时的指定值
///
[DefaultValue(Visibility.Hidden)]
public Visibility VisibilityOnFalse
{
get => (Visibility)GetValue(TargetBoolValueProperty);
set => SetValue(TargetBoolValueProperty, value);
}
///
///
///
///
///
///
///
///
///
public override object Convert(
object[] values,
Type targetType,
object parameter,
CultureInfo culture
)
{
var boolValue = TargetBoolValue;
var nullValue = BoolOnNull;
return values.All(o => Utils.GetBool(o, boolValue, nullValue))
? VisibilityOnTrue
: VisibilityOnFalse;
}
}