-
Notifications
You must be signed in to change notification settings - Fork 2
/
NegativeValueConverter.cs
37 lines (34 loc) · 1.22 KB
/
NegativeValueConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace ReorderListBoxDemo
{
public class NegativeValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType == typeof(double))
{
return -System.Convert.ToDouble(value);
}
else if (targetType == typeof(Thickness))
{
double doubleValue = -System.Convert.ToDouble(value);
switch ((string)parameter)
{
case "Left": return new Thickness(doubleValue, 0, 0, 0);
case "Top": return new Thickness(0, doubleValue, 0, 0);
case "Right": return new Thickness(0, 0, doubleValue, 0);
case "Bottom": return new Thickness(0, 0, 0, doubleValue);
default: return new Thickness(doubleValue);
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}