2020-11-27 18:51:02 +08:00
|
|
|
using System;
|
|
|
|
using System.Globalization;
|
2020-12-12 23:19:47 +08:00
|
|
|
using System.Windows;
|
2020-11-27 18:51:02 +08:00
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
|
|
namespace BililiveRecorder.WPF.Converters
|
|
|
|
{
|
2020-12-12 23:19:47 +08:00
|
|
|
internal class BoolToValueConverter : DependencyObject, IValueConverter
|
2020-11-27 18:51:02 +08:00
|
|
|
{
|
2020-12-12 23:19:47 +08:00
|
|
|
public static readonly DependencyProperty TrueValueProperty = DependencyProperty.Register(nameof(TrueValue), typeof(object), typeof(BoolToValueConverter), new PropertyMetadata(null));
|
|
|
|
public static readonly DependencyProperty FalseValueProperty = DependencyProperty.Register(nameof(FalseValue), typeof(object), typeof(BoolToValueConverter), new PropertyMetadata(null));
|
|
|
|
|
|
|
|
public object TrueValue { get => GetValue(TrueValueProperty); set => SetValue(TrueValueProperty, value); }
|
|
|
|
public object FalseValue { get => GetValue(FalseValueProperty); set => SetValue(FalseValueProperty, value); }
|
2020-11-27 18:51:02 +08:00
|
|
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
{
|
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
return FalseValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (bool)value ? TrueValue : FalseValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
{
|
|
|
|
return value != null ? value.Equals(TrueValue) : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|