Exemple #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]);
        }
Exemple #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);
        }
Exemple #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 Thickness))
            {
                throw new ArgumentException("The parameter of this converter must be an instance of the Thickness structure. Use {sd: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);
        }
Exemple #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 Size))
            {
                throw new ArgumentException("The parameter of this converter must be an instance of the Size structure. Use {sd: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 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);
        }
 /// <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);
 }
Exemple #7
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));
 }
Exemple #8
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);
        }
Exemple #9
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));
 }
Exemple #10
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));
 }
Exemple #11
0
        /// <inheritdoc/>
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var result = !ConverterHelper.ConvertToBoolean(value, culture);

            return(result.Box());
        }
Exemple #12
0
 /// <inheritdoc/>
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return targetType == typeof(double) ? ConverterHelper.ConvertToDouble(value, culture) : ConverterHelper.TryConvertToDouble(value, culture);
 }
Exemple #13
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);
        }
Exemple #14
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);
 }