/// <summary> /// Converts a value. /// </summary> /// <param name="value">The value that is produced by the binding target.</param> /// <param name="targetType">The type to convert to.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> /// <returns> /// A converted value. If the method returns <c>null</c>, the valid <c>null</c> value is used. /// </returns> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var input = value as string; if (input == null) { return(DependencyProperty.UnsetValue); } if (targetType != typeof(TimeSpan)) { return(DependencyProperty.UnsetValue); } var formatString = parameter as string; if (string.IsNullOrWhiteSpace(formatString)) { return(TimeSpan.Parse(input)); } var parser = new FormattedTimeSpanParser(formatString); return(parser.Parse(input)); }
/// <summary> /// Converts a value. /// </summary> /// <param name="value"> /// The value that is produced by the binding target. /// </param> /// <param name="targetType"> /// The type to convert to. /// </param> /// <param name="parameter"> /// The converter parameter to use. /// </param> /// <param name="culture"> /// The culture to use in the converter. /// </param> /// <returns> /// A converted value. If the method returns null, the valid null value is used. /// </returns> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var input = value as string; if (input == null) { return Binding.DoNothing; } if (targetType != typeof(TimeSpan)) { return Binding.DoNothing; } var formatstring = parameter as string; if (string.IsNullOrWhiteSpace(formatstring)) { return TimeSpan.Parse(input); } var parser = new FormattedTimeSpanParser(formatstring); return parser.Parse(input); }