Esempio n. 1
0
        protected bool Validate()
        {
            var previousResults = _validationResults;
            var validator       = ProvideValidator();

            _validationResults = validator.Validate(this);

            // raise errors changed event for union set of previous and current results
            // so a change notification is raised for each affected property
            var propertiesInError =
                previousResults
                .GetPropertiesInError()
                .Union(_validationResults.GetPropertiesInError())
                .Distinct();

            // HasErrors must be true before raising the ErrorsChanged event, otherwise WPF will ignore the errors !!
            // Thx to http://stackoverflow.com/a/24837028 for this hint ;-)
            IsValid   = _validationResults.IsValid;
            HasErrors = !IsValid;

            foreach (var property in propertiesInError)
            {
                RaiseErrorsChanged(property);
            }

            _validationSubject.OnNext(_validationResults);
            return(_validationResults.IsValid);
        }