Bennedik.Validation.Integration.WPF.ErrorProvider.Validate C# (CSharp) Method

Validate() public method

Validates all properties on the current data source.
Note that only errors on properties that are displayed are included. Other errors, such as errors for properties that are not displayed, will not be validated by this method.
public Validate ( ) : bool
return bool
        public bool Validate()
        {
            bool isValid = true;
            _firstInvalidElement = null;
            errorMessages = new List<string>();

            FindBindingsRecursively(Parent,
                delegate(FrameworkElement element, Binding binding, DependencyProperty dp)
                {
                    foreach (ValidationRule rule in binding.ValidationRules)
                    {
                        System.Windows.Controls.ValidationResult valid = rule.Validate(element.GetValue(dp), CultureInfo.CurrentUICulture);
                        if (!valid.IsValid)
                        {
                            if (isValid)
                            {
                                isValid = false;
                                _firstInvalidElement = element;
                            }

                            BindingExpression expression = element.GetBindingExpression(dp);
                            ValidationError error = new ValidationError(rule, expression, valid.ErrorContent, null);
                            System.Windows.Controls.Validation.MarkInvalid(expression, error);

                            string errorMessage = valid.ErrorContent.ToString();
                            if (!errorMessages.Contains(errorMessage))
                                errorMessages.Add(errorMessage);
                        }
                    }
                });

            return isValid;
        }