using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace mdfinder
{
/// An inverse boolean converter.
/// This code is derived from code in the butterflow-ui project. https://github.com/wagesj45/butterflow-ui
[ValueConversion(typeof(bool), typeof(bool))]
public class InverseBoolConverter : IValueConverter
{
/// Converts a boolean to its inverse.
/// Thrown when an object cannot be cast to a required
/// type.
/// The value produced by the binding source.
/// The type of the binding target property.
/// The converter parameter to use.
/// The culture to use in the converter.
///
/// A converted value. If the method returns , the valid null value is
/// used.
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType == typeof(bool))
{
return !(bool)value;
}
throw new InvalidCastException(string.Format(Localization.Localization.BooleanInvalidCastExceptionFormat, targetType.Name));
}
/// Converts an inverse boolean back to its original state.
/// Thrown when an object cannot be cast to a required
/// type.
/// The value that is produced by the binding target.
/// The type to convert to.
/// The converter parameter to use.
/// The culture to use in the converter.
///
/// A converted value. If the method returns , the valid null value is
/// used.
///
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType == typeof(bool))
{
return !(bool)value;
}
throw new InvalidCastException(string.Format(Localization.Localization.BooleanInvalidCastExceptionFormat, targetType.Name));
}
}
}