public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                int result = int.Parse((string)value);

                if (errorDisplay.IsError)
                {
                    if (errorDisplay.ErrorField == bindingProperty)
                    {
                        errorDisplay.ErrorField = null;
                    }
                    errorDisplay.ResetFeedback();
                }

                return(result);
            }
            catch (Exception)
            {
                errorDisplay.ErrorField = bindingProperty;
                errorDisplay.IsError    = true;
                errorDisplay.Feedback   = "Could not convert text into a positive integer";
                return(DependencyProperty.UnsetValue);
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                double conversion = Double.Parse((string)value);

                if (conversion < 0 || conversion > 4)
                {
                    throw new ArgumentOutOfRangeException();
                }

                if (errorDisplay.IsError)
                {
                    if (errorDisplay.ErrorField == bindingProperty)
                    {
                        errorDisplay.ErrorField = null;
                    }
                    errorDisplay.ResetFeedback();
                }

                return(value);
            } catch (Exception)
            {
                errorDisplay.ErrorField = bindingProperty;
                errorDisplay.IsError    = true;
                errorDisplay.Feedback   = "Could not convert text into a number between 0 and 4.0 inclusive";
                return(DependencyProperty.UnsetValue);
            }
        }
예제 #3
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string input = value.ToString();

            foreach (char c in input)
            {
                if (!Char.IsDigit(c))
                {
                    errorDisplay.ErrorField = bindingProperty;
                    errorDisplay.IsError    = true;
                    errorDisplay.Feedback   = "Student ID can only be a number";
                    return(DependencyProperty.UnsetValue);
                }
            }

            if (errorDisplay.IsError)
            {
                if (errorDisplay.ErrorField == bindingProperty)
                {
                    errorDisplay.ErrorField = null;
                }
                errorDisplay.ResetFeedback();
            }

            return(value);
        }