コード例 #1
0
        private void OnPropertyValidated(string propertyName, string error, bool notifyIfSameValidity = false)
        {
            if (!_enabled)
            {
                return;
            }

            var    errorsChanged = false;
            string oldError;

            if (!Errors.TryGetValue(propertyName, out oldError) || error != oldError)
            {
                errorsChanged        = true;
                Errors[propertyName] = error;
                OnPropertyChanged("Errors");
            }

            var oldValidity = IsValid;

            if (errorsChanged)
            {
                IsValid = Errors.All(e => string.IsNullOrEmpty(e.Value));
            }
            if (IsValid != oldValidity || notifyIfSameValidity)
            {
                OnPropertyChanged("IsValid");
            }
        }