public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null) { throw new ArgumentNullException(nameof(values)); } switch (values.Length) { case 1: var uniform = ConverterHelper.ConvertToDouble(values[0], culture); return(new Thickness(uniform)); case 2: var horizontal = ConverterHelper.ConvertToDouble(values[0], culture); var vertical = ConverterHelper.ConvertToDouble(values[1], culture); return(new Thickness(horizontal, vertical, horizontal, vertical)); case 4: var left = ConverterHelper.ConvertToDouble(values[0], culture); var top = ConverterHelper.ConvertToDouble(values[1], culture); var right = ConverterHelper.ConvertToDouble(values[2], culture); var bottom = ConverterHelper.ConvertToDouble(values[3], culture); return(new Thickness(left, top, right, bottom)); default: throw new ArgumentException($"Inconsistent number of parameters: expected 1, 2 or 4 values, got {values.Length}.", nameof(values)); } }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var doubleValue = ConverterHelper.ConvertToDouble(value, culture); var doubleParameter = ConverterHelper.ConvertToDouble(parameter, culture); return(System.Convert.ChangeType(Math.Max(doubleValue, doubleParameter), value?.GetType() ?? targetType)); }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var doubleValue = ConverterHelper.ConvertToDouble(value, culture); var doubleParameter = ConverterHelper.ConvertToDouble(parameter, culture); return(Compare(doubleValue, doubleParameter)); }
/// <inheritdoc/> public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { double scalar; try { scalar = ConverterHelper.ConvertToDouble(value, culture); } catch (Exception exception) { throw new ArgumentException("The value of this converter must be convertible to a double.", exception); } double param; try { param = ConverterHelper.ConvertToDouble(parameter, culture); } catch (Exception exception) { throw new ArgumentException("The parameter of this converter must be convertible to a double.", exception); } if (Math.Abs(param) > double.Epsilon) { return(System.Convert.ChangeType(scalar / param, targetType)); } return(DependencyProperty.UnsetValue); }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double scalar; try { scalar = ConverterHelper.ConvertToDouble(value, culture); } catch (Exception exception) { throw new ArgumentException("The value of this converter must be convertible to a double.", exception); } double param; try { param = ConverterHelper.ConvertToDouble(parameter, culture); } catch (Exception exception) { throw new ArgumentException("The parameter of this converter must be convertible to a double.", exception); } return(System.Convert.ChangeType(scalar * param, targetType)); }
/// <inheritdoc/> public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var doubleValue = ConverterHelper.ConvertToDouble(value, culture); var doubleParameter = ConverterHelper.ConvertToDouble(parameter, culture); var result = doubleValue - doubleParameter; return(System.Convert.ChangeType(result, targetType)); }
public override object Convert([NotNull] object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Length < 2) { throw new InvalidOperationException("This multi converter must be invoked with at least two elements"); } var result = 1.0; try { result = values.Select(x => ConverterHelper.ConvertToDouble(x, culture)).Aggregate(result, (current, next) => current * next); } catch (Exception exception) { throw new ArgumentException("The values of this converter must be convertible to a double.", exception); } return(result); }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double scalar; try { scalar = ConverterHelper.ConvertToDouble(value, culture); } catch (Exception exception) { throw new ArgumentException("The value of this converter must be convertible to a double.", exception); } if (!(parameter is Size)) { throw new ArgumentException("The parameter of this converter must be an instance of the Size structure. Use {sskk:Size (arguments)} to construct one."); } var size = (Size)parameter; var result = new Size(size.Width * scalar, size.Height * scalar); return(result); }
/// <inheritdoc/> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double scalar; try { scalar = ConverterHelper.ConvertToDouble(value, culture); } catch (Exception exception) { throw new ArgumentException("The value of this converter must be convertible to a double.", exception); } if (!(parameter is Thickness)) { throw new ArgumentException("The parameter of this converter must be an instance of the Thickness structure. Use {sskk:Thickness (arguments)} to construct one."); } var thickness = (Thickness)parameter; var result = new Thickness(thickness.Left * scalar, thickness.Top * scalar, thickness.Right * scalar, thickness.Bottom * scalar); return(result); }
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var seconds = ConverterHelper.ConvertToDouble(value, culture); return(TimeSpan.FromSeconds(seconds)); }