功能更新
This commit is contained in:
30
Melskin/Converters/Internal/NegativeConverter.cs
Normal file
30
Melskin/Converters/Internal/NegativeConverter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user