Example #1
0
            public object ConvertBack(object obj, Type targetType, object parameter, out ValidationResult validationResult)
            {
                validationResult = ValidationResult.ValidResult;

                string s = (string)obj;

                if (null != _parent)
                {
                    _parent.SetValue(ValueStringPropertyKey, s); // we set the value string property to have the actual text value as a property
                    s = s.Trim();

                    if (!string.IsNullOrEmpty(_parent.MinimumReplacementText) && _parent.MinimumReplacementText.Trim() == s)
                    {
                        return(_parent.Minimum);
                    }
                    else if (!string.IsNullOrEmpty(_parent.MaximumReplacementText) && _parent.MaximumReplacementText.Trim() == s)
                    {
                        return(_parent.Maximum);
                    }
                    else if (string.IsNullOrEmpty(s) && null != _parent.ValueIfTextIsEmpty)
                    {
                        return(_parent.ValueIfTextIsEmpty);
                    }
                }

                if (int.TryParse(s, NumberStyles.Integer, _conversionCulture, out var result))
                {
                    return(result);
                }
                else
                {
                    validationResult = new ValidationResult(false, string.Format("The provided string could not be converted to an integer value!"));
                    return(System.Windows.Data.Binding.DoNothing);
                }
            }