public static void RemoveErrorForProperty(this INotifyDataErrorInfoEx notifyErrorInfo, string property, int errorCode)
        {
            bool oldHasErrors = notifyErrorInfo.HasErrors;
            var  errors       = notifyErrorInfo.Errors;

            if (errors.ContainsKey(property))
            {
                var propertyErrors = errors[property];
                var errorInfo      = propertyErrors.SingleOrDefault(e => e.ErrorCode == errorCode);
                if (errorInfo != null)
                {
                    // remove error for property
                    propertyErrors.Remove(errorInfo);
                    if (propertyErrors.Count == 0)
                    {
                        // property is valid
                        errors.Remove(property);
                    }

                    notifyErrorInfo.RaiseErrorsChanged(property);
                }
            }

            if (oldHasErrors != notifyErrorInfo.HasErrors)
            {
                //OnHasErrorsChanged();
                notifyErrorInfo.RaisePropertyChangedEx(m => m.HasErrors);
            }
        }
        public static void AddErrorForProperty(this INotifyDataErrorInfoEx notifyErrorInfo, string property, int errorCode, string errorMessage)
        {
            var  errors       = notifyErrorInfo.Errors;
            bool oldHasErrors = notifyErrorInfo.HasErrors;

            if (!errors.ContainsKey(property))
            {
                errors.Add(property, new List <ValidationErrorInfo>());
            }

            var propertyErrors = errors[property];

            if (propertyErrors.SingleOrDefault(e => e.ErrorCode == errorCode) == null)
            {
                var errorInfo = new ValidationErrorInfo();
                errorInfo.ErrorCode    = errorCode;
                errorInfo.ErrorMessage = errorMessage;
                propertyErrors.Add(errorInfo);
                notifyErrorInfo.RaiseErrorsChanged(property);
            }

            if (oldHasErrors != notifyErrorInfo.HasErrors)
            {
                notifyErrorInfo.RaisePropertyChangedEx(m => m.HasErrors);
                //OnHasErrorsChanged();
            }
        }
        private static void RemoveAllErrorsForProperty(this INotifyDataErrorInfoEx notifyErrorInfo, string propertyName)
        {
            if (notifyErrorInfo.Errors.ContainsKey(propertyName))
            {
                notifyErrorInfo.Errors.Remove(propertyName);
                notifyErrorInfo.RaiseErrorsChanged(propertyName);
            }

            notifyErrorInfo.RaisePropertyChangedEx(m => m.HasErrors);
        }
        public static void ClearErrors(this INotifyDataErrorInfoEx notifyErrorInfo)
        {
            if (notifyErrorInfo.Errors.Count == 0)
            {
                return;
            }
            var errors = notifyErrorInfo.Errors;

            foreach (var propertyName in errors.Keys)
            {
                notifyErrorInfo.Errors[propertyName].Clear();
                notifyErrorInfo.RaiseErrorsChanged(propertyName);
            }

            errors.Clear();
            notifyErrorInfo.RaisePropertyChangedEx(m => m.HasErrors);
        }