VPet/VPet.Solution/Converters/BoolToVisibilityConverter.cs

63 lines
1.7 KiB
C#
Raw Permalink Normal View History

2023-12-30 15:50:37 +00:00
using System.ComponentModel;
using System.Globalization;
using System.Windows;
namespace HKW.WPF.Converters;
public class BoolToVisibilityConverter : BoolToValueConverterBase<BoolToVisibilityConverter>
{
/// <summary>
///
/// </summary>
public static readonly DependencyProperty TrueVisibilityValueProperty =
DependencyProperty.Register(
nameof(TrueVisibilityValue),
typeof(Visibility),
2024-01-09 15:22:25 +00:00
typeof(BoolToVisibilityConverter),
2023-12-30 15:50:37 +00:00
new PropertyMetadata(Visibility.Visible)
);
/// <summary>
/// 为真时的可见度
/// </summary>
[DefaultValue(Visibility.Visible)]
public Visibility TrueVisibilityValue
{
get => (Visibility)GetValue(TrueVisibilityValueProperty);
set => SetValue(TrueVisibilityValueProperty, value);
}
/// <summary>
///
/// </summary>
public static readonly DependencyProperty FalseVisibilityValueProperty =
DependencyProperty.Register(
nameof(FalseVisibilityValue),
typeof(Visibility),
2024-01-09 15:22:25 +00:00
typeof(BoolToVisibilityConverter),
2023-12-30 15:50:37 +00:00
new PropertyMetadata(Visibility.Hidden)
);
/// <summary>
/// 为假时的可见度
/// </summary>
[DefaultValue(Visibility.Hidden)]
public Visibility FalseVisibilityValue
{
get => (Visibility)GetValue(FalseVisibilityValueProperty);
set => SetValue(FalseVisibilityValueProperty, value);
}
public override object Convert(
object value,
Type targetType,
object parameter,
CultureInfo culture
)
{
return HKWUtils.HKWUtils.GetBool(value, BoolValue, NullValue)
2023-12-30 15:50:37 +00:00
? TrueVisibilityValue
: FalseVisibilityValue;
}
}