Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ValueConversion(typeof(double), typeof(double))]
- public class DecreaseDoubleConverter : ValueGenericConverter<double>
- {
- protected override Func<object, CultureInfo, double> ConvertMethod =>
- (value, culture) =>
- {
- if (value == null)
- return 0;
- var result = System.Convert.ToDouble(value);
- return double.IsNaN(result) ? 0 : result;
- };
- }
- public abstract class ValueGenericConverter<T> : BaseGenericConverter<T>, IValueConverter where T : new()
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- Debug.Assert(targetType.IsAssignableFrom(typeof(T)), string.Format("targetType should be {typeof(T).FullName}"));
- var tResult = new T();
- if (!Convert(value, culture, ref tResult))
- return DependencyProperty.UnsetValue;
- ApplyParameter(parameter, culture, ref tResult);
- return System.Convert.ChangeType(tResult, targetType);
- }
- }
- public abstract class BaseGenericConverter<T>
- {
- protected abstract Func<object, CultureInfo, T> ConvertMethod { get; }
- protected Func<T, T, T> ApplyParameterMethod = null;
- }
Add Comment
Please, Sign In to add comment