using System; using System.Globalization; using System.Windows.Data; namespace Melskin.Converters.Internal { internal class NegativeConverter : IValueConverter { public static readonly NegativeConverter Instance = new NegativeConverter(); public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { //if (value is double d) return -d; //if (value is int i) return -i; //if (value is float f) return -f; //if (value is decimal dec) return -dec; //if (value is long l) return -l; if (value is Thickness thickness) { return new Thickness(-thickness.Left, -thickness.Top, -thickness.Right, -thickness.Bottom); } // 也可以使用 Convert.ToDouble 进行更通用的转换 return -(System.Convert.ToDouble(value)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }