예제 #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]);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #5
0
 /// <inheritdoc/>
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var result = !ConverterHelper.ConvertToBoolean(value, culture);
     return result.Box();
 }
예제 #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);
        }
예제 #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);
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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);
        }
예제 #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);
        }
예제 #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);
 }