Exemplo n.º 1
0
        /// <inheritdoc/>
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var collection = parameter as IList;

            if (collection == null)
            {
                return(null);
            }

            var index = ConverterHelper.ConvertToInt32(value ?? -1, culture);

            if (index < 0 || index >= collection.Count)
            {
                return(null);
            }

            return(collection[index]);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 /// <inheritdoc/>
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var result = !ConverterHelper.ConvertToBoolean(value, culture);
     return result.Box();
 }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var doubleValue = targetType == typeof(AngleSingle) ? ConverterHelper.ConvertToDouble(value, culture) : ConverterHelper.TryConvertToDouble(value, culture);

            return(doubleValue != null ? (object)new AngleSingle((float)doubleValue.Value, AngleType.Degree) : null);
        }
Exemplo n.º 7
0
 /// <inheritdoc/>
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(targetType == typeof(double) ? ConverterHelper.ConvertToAngleSingle(value, culture).Degrees : ConverterHelper.TryConvertToAngleSingle(value, culture)?.Degrees);
 }
Exemplo n.º 8
0
 /// <inheritdoc/>
 public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(targetType == typeof(char) ? ConverterHelper.ConvertToChar(value, culture) : ConverterHelper.TryConvertToChar(value, culture));
 }
Exemplo n.º 9
0
 /// <inheritdoc/>
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(targetType == typeof(int) ? ConverterHelper.ConvertToInt32(value, culture) : ConverterHelper.TryConvertToInt32(value, culture));
 }
Exemplo n.º 10
0
 /// <inheritdoc/>
 public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(targetType.IsValueType && !targetType.IsNullable() ? ConverterHelper.ChangeType(value, targetType, culture) : ConverterHelper.TryChangeType(value, targetType, culture));
 }
Exemplo n.º 11
0
        /// <inheritdoc/>
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var result = ConverterHelper.ConvertToBoolean(value, culture);

            return(result ? parameter : DependencyProperty.UnsetValue);
        }
Exemplo n.º 12
0
        /// <inheritdoc/>
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var doubleValue = targetType == typeof(TimeSpan) ? ConverterHelper.ConvertToDouble(value, culture) : ConverterHelper.TryConvertToDouble(value, culture);

            return(doubleValue != null ? (object)TimeSpan.FromSeconds(doubleValue.Value) : null);
        }
Exemplo n.º 13
0
 /// <inheritdoc/>
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(targetType == typeof(double) ? ConverterHelper.ConvertToTimeSpan(value, culture).TotalSeconds : ConverterHelper.TryConvertToTimeSpan(value, culture)?.TotalSeconds);
 }