4 using System.Globalization;
6 using System.Windows.Data;
8 namespace SiliconStudio.Presentation.ValueConverters
13 [ValueConversion(typeof(
double), typeof(
double))]
14 public class Multiply : ValueConverterBase<Multiply>
17 public override object Convert(
object value, Type targetType,
object parameter, CultureInfo culture)
22 scalar = System.Convert.ToDouble(value, culture);
26 throw new ArgumentException(
"The value of this converter must be convertible to a double.", exception);
32 param = System.Convert.ToDouble(parameter, culture);
36 throw new ArgumentException(
"The parameter of this converter must be convertible to a double.", exception);
39 return System.Convert.ChangeType(scalar * param, targetType);
43 public override object ConvertBack(
object value, Type targetType,
object parameter, CultureInfo culture)
48 scalar = System.Convert.ToDouble(value, culture);
52 throw new ArgumentException(
"The value of this converter must be convertible to a double.", exception);
58 param = System.Convert.ToDouble(parameter, culture);
62 throw new ArgumentException(
"The parameter of this converter must be convertible to a double.", exception);
65 if (Math.Abs(param) > double.Epsilon)
67 return System.Convert.ChangeType(scalar / param, targetType);
70 return DependencyProperty.UnsetValue;
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
This converter will multiply a given numeric value by the numeric value given as parameter.