示例#1
0
        /// <summary>
        /// Applies Formatter to input.
        /// </summary>
        /// <param name="value">Input to Formatter.</param>
        /// <param name="targetType">Unused. Assumed System.String.</param>
        /// <param name="parameter">Unused.</param>
        /// <param name="culture">Unused.</param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value?.Equals(DependencyProperty.UnsetValue) ?? false)
            {
                return(Binding.DoNothing);
            }

            string scrubbedText =
                Utilities.Perform.TextScrub(new[] { value?.ToString() ?? "" }, ScrubCharacters?.Select(c => System.Convert.ToChar(c)).ToArray()).FirstOrDefault() ?? "";

            string formattedText = Formatter?.Format(scrubbedText) ?? "";

            return(string.IsNullOrEmpty(formattedText) ? (EmptyText == null ? scrubbedText : EmptyText) : formattedText);
        }
        /// <summary>
        /// Applies Formatter to inputs.
        /// </summary>
        /// <param name="values">Input to Formatter.</param>
        /// <param name="targetType">Unused. Assumed <see cref="System.String"/>.</param>
        /// <param name="parameter">Unused.</param>
        /// <param name="culture">Unused.</param>
        /// <returns></returns>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values?.All(v => v == null || v.Equals("") || v.Equals(DependencyProperty.UnsetValue)) ?? true)
            {
                return(DependencyProperty.UnsetValue);
            }

            var stringValues = values?.Select(v =>
                                              v?.Equals(DependencyProperty.UnsetValue) ?? true ?
                                              "" :
                                              Utilities.Perform.TextScrub(new[] { v?.ToString() ?? "" }, ScrubCharacters?.Select(c => System.Convert.ToChar(c)).ToArray()).FirstOrDefault() ?? ""
                                              )
                               .ToArray() ?? new string[0];
            string formattedText = Formatter?.Format(stringValues) ?? "";

            return(string.IsNullOrEmpty(formattedText) ? (EmptyText == null ? "" : EmptyText) : formattedText);
        }