made DoubleSubtractionConverter (IValueConverter) and DoubleDynamicSubtractionConverter (IMultiValueConverter)

This commit is contained in:
John Colvin committed 2019-04-03 13:46:42 -05:00
1 parent fe50e40524
commit c0155047a8
1 file changed
+41
@@ -0,0 +1,41 @@
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
namespace mbts.ui.converters {
[ValueConversion(typeof(double), typeof(double))]
class DoubleSubtractionConverter : IValueConverter {
public double Value { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value is double d)
return d - Value;
return new ValidationResult(false, "Not a double.");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
if (value is double d)
return d + Value;
return new ValidationResult(false, "Not a double.");
}
}
[ValueConversion(typeof(double[]), typeof(double))]
class DoubleDynamicSubtractionConverter : IMultiValueConverter {
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
if (values.Length > 0 && values[0] is double difference) {
for (int i = 1; i < values.Length; i++) {
if (values[i] is double v)
difference -= v;
}
return difference;
}
return new ValidationResult(false, "No doubles.");
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) =>
throw new NotImplementedException();
}
}