Ejemplo n.º 1
0
 internal static void RemoveValidationError(UIElement fe, ValidationError error)
 {
     ObservableCollection<ValidationError> internalErrors = Validation.GetInternalErrors(fe);
     if (internalErrors == null || internalErrors.Count == 0)
     {
         return;
     }
     internalErrors.Remove(error);
     if (internalErrors.Count == 0)
     {
         fe.SetValue(Validation.HasErrorProperty, false);
         if (fe is Control)
         {
             ((Control)fe).HideValidationError();
         }
     }
 }
Ejemplo n.º 2
0
 internal static void AddValidationError(UIElement fe, ValidationError error)
 {
     ObservableCollection<ValidationError> internalErrors = Validation.GetInternalErrors(fe);
     ReadOnlyObservableCollection<ValidationError> errors = Validation.GetErrors(fe);
     bool hasError = Validation.GetHasError(fe);
     if (internalErrors == null)
     {
         internalErrors = new ObservableCollection<ValidationError>();
         errors = new ReadOnlyObservableCollection<ValidationError>(internalErrors);
         fe.SetValue(Validation.InternalErrorsProperty, internalErrors);
         fe.SetValue(Validation.ErrorsProperty, errors);
     }
     internalErrors.Add(error);
     fe.SetValue(Validation.HasErrorProperty, true);
     if (!hasError && fe is Control)
     {
         ((Control)fe).ShowValidationError();
     }
 }
Ejemplo n.º 3
0
 internal ValidationErrorEventArgs(ValidationErrorEventAction action, ValidationError error)
 {
     this.Action = action;
     this.Error = error;
     this.Handled = false;
 }
Ejemplo n.º 4
0
 private void AddErrorNotificationToQueue(ValidationErrorEventAction action, ValidationError error)
 {
     if (!this.binding.NotifyOnValidationError || error == null || this.TargetElement == null)
     {
         return;
     }
     ValidationErrorEventArgs validationErrorEventArg = new ValidationErrorEventArgs(action, error);
     if (this.errorNotifications == null)
     {
         this.errorNotifications = new List<ValidationErrorEventArgs>();
     }
     this.errorNotifications.Add(validationErrorEventArg);
 }
 internal ValidationErrorEventArgs(ValidationErrorEventAction action, ValidationError error)
 {
     this.Action  = action;
     this.Error   = error;
     this.Handled = false;
 }
Ejemplo n.º 6
0
 internal void SendDataToTarget()
 {
     ValidationError validationError = null;
     if (this.updateState == BindingExpression.UpdateState.None && this.binding.ValidatesOnDataErrors)
     {
         string dataErrorInfoMessage = this.GetDataErrorInfoMessage();
         if (!string.IsNullOrEmpty(dataErrorInfoMessage))
         {
             validationError = new ValidationError(dataErrorInfoMessage);
         }
     }
     if (validationError == null)
     {
         this.RemoveErrorFromTarget(this.currentValidationError);
         this.AddErrorNotificationToQueue(ValidationErrorEventAction.Removed, this.currentValidationError);
         this.RaiseErrorNotifications();
         this.currentValidationError = null;
     }
     BindingExpression.UpdateState updateState = this.updateState;
     this.updateState = BindingExpression.UpdateState.UpdatingTarget;
     try
     {
         this.RefreshExpression();
     }
     catch (Exception e)
     {
         Debug.WriteLine(string.Format("Exception occured during binding: {0}\nStackTrace:\n{1}", e.Message, e.StackTrace));
     #if DEBUG
         throw;
     #endif
     }
     finally
     {
         this.updateState = updateState;
     }
     if (validationError != null)
     {
         this.AddErrorNotificationToQueue(ValidationErrorEventAction.Removed, this.currentValidationError);
         this.AddErrorNotificationToQueue(ValidationErrorEventAction.Added, validationError);
     }
     if (updateState != BindingExpression.UpdateState.UpdatingSource && this.lastSourceUpdateThrewException)
     {
         this.lastSourceUpdateThrewException = false;
         this.AddNotifyDataErrorInfosToQueue(ValidationErrorEventAction.Added);
         this.AddNotifyDataErrorInfosToTarget();
     }
     if (validationError != null)
     {
         ValidationError validationError1 = this.currentValidationError;
         this.AddErrorToTarget(validationError, false);
         this.RemoveErrorFromTarget(validationError1);
     }
     this.RaiseErrorNotifications();
 }
Ejemplo n.º 7
0
 internal void RemoveErrorFromTarget(ValidationError error)
 {
     if (this.TargetElement == null || error == null)
     {
         return;
     }
     Validation.RemoveValidationError(this.TargetElement, error);
 }
Ejemplo n.º 8
0
 internal void EndSetBinding()
 {
     if (this.binding.ValidatesOnDataErrors)
     {
         string dataErrorInfoMessage = this.GetDataErrorInfoMessage();
         if (!string.IsNullOrEmpty(dataErrorInfoMessage))
         {
             ValidationError validationError = new ValidationError(dataErrorInfoMessage);
             this.AddErrorNotificationToQueue(ValidationErrorEventAction.Added, validationError);
             this.AddErrorToTarget(validationError, false);
             this.RaiseErrorNotifications();
         }
     }
     if (this.binding.ValidatesOnNotifyDataErrors)
     {
         this.ConsumeNotifyDataErrorInfo();
     }
     this.updateState = BindingExpression.UpdateState.None;
 }
Ejemplo n.º 9
0
 internal void AddErrorToTarget(ValidationError error, bool isNotifyDataErrorInfo)
 {
     if (this.TargetElement == null)
     {
         return;
     }
     if (!isNotifyDataErrorInfo)
     {
         this.currentValidationError = error;
     }
     if (error == null)
     {
         return;
     }
     Validation.AddValidationError(this.TargetElement, error);
 }
Ejemplo n.º 10
0
 private void UpdateValue()
 {
     Exception innerException = null;
     string dataErrorInfoMessage = null;
     CultureInfo cultureInfo = null;
     bool flag = false;
     if (this.listener == null || !this.listener.FullPathExists)
     {
         return;
     }
     this.updateState = BindingExpression.UpdateState.UpdatingSource;
     try
     {
         object value = this.targetDO.GetValue(this.targetProperty);
         if (this.binding.TargetNullValue != null)
         {
             object targetNullValue = null;
             try
             {
                 Type type = this.binding.TargetNullValue.GetType();
                 if (type == this.targetProperty.PropertyType || this.targetProperty.PropertyType.IsAssignableFrom(type))
                 {
                     targetNullValue = this.binding.TargetNullValue;
                 }
                 else
                 {
                     if (cultureInfo == null)
                     {
                         cultureInfo = this.CalculateCulture();
                     }
                     targetNullValue = this.DynamicConverter.Convert(this.binding.TargetNullValue, this.targetProperty.PropertyType, null, cultureInfo);
                 }
                 if (object.Equals(value, targetNullValue))
                 {
                     value = null;
                 }
             }
             catch (Exception e)
             {
                 Debug.WriteLine(e.ToString());
             }
         }
         if (this.binding.Converter != null)
         {
             if (cultureInfo == null)
             {
                 cultureInfo = this.CalculateCulture();
             }
             value = this.binding.Converter.ConvertBack(value, this.listener.LeafType, this.binding.ConverterParameter, cultureInfo);
             if (value == DependencyProperty.UnsetValue)
             {
                 return;
             }
         }
         if (value != null && value is string)
         {
             if (cultureInfo == null)
             {
                 cultureInfo = this.CalculateCulture();
             }
             object obj = BindingExpression.TryParse(value, this.listener.LeafType, cultureInfo);
             if (obj != DependencyProperty.UnsetValue)
             {
                 value = obj;
             }
         }
         try
         {
             if (!this.IsValidValueForUpdate(value, this.listener.LeafType))
             {
                 if (cultureInfo == null)
                 {
                     cultureInfo = this.CalculateCulture();
                 }
                 flag = true;
                 value = this.DynamicConverter.Convert(value, this.listener.LeafType, null, cultureInfo);
                 flag = false;
             }
             this.listener.LeafValue = value;
         }
         catch (TargetInvocationException targetInvocationException)
         {
             Debug.WriteLine(targetInvocationException.ToString());
             innerException = targetInvocationException.InnerException;
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.ToString());
             if (e is OutOfMemoryException || e is StackOverflowException || e is AccessViolationException || e is ThreadAbortException)
             {
                 throw;
             }
         }
     }
     finally
     {
         if (this.binding.ValidatesOnDataErrors && (innerException == null || !this.binding.ValidatesOnExceptions))
         {
             dataErrorInfoMessage = this.GetDataErrorInfoMessage();
         }
         this.updateState = BindingExpression.UpdateState.None;
         this.targetPropertyState = BindingExpression.TargetPropertyState.Clean;
     }
     ValidationError validationError = null;
     if (innerException != null && this.binding.ValidatesOnExceptions)
     {
         validationError = new ValidationError(innerException, flag);
     }
     else if (!string.IsNullOrEmpty(dataErrorInfoMessage))
     {
         validationError = new ValidationError(dataErrorInfoMessage);
     }
     bool flag1 = innerException != null;
     if (flag1 && !this.lastSourceUpdateThrewException)
     {
         this.AddNotifyDataErrorInfosToQueue(ValidationErrorEventAction.Removed);
     }
     this.AddErrorNotificationToQueue(ValidationErrorEventAction.Removed, this.currentValidationError);
     if (!flag1 && this.lastSourceUpdateThrewException)
     {
         this.AddNotifyDataErrorInfosToQueue(ValidationErrorEventAction.Added);
     }
     this.AddErrorNotificationToQueue(ValidationErrorEventAction.Added, validationError);
     ValidationError validationError1 = this.currentValidationError;
     if (this.lastSourceUpdateThrewException && !flag1)
     {
         this.AddNotifyDataErrorInfosToTarget();
     }
     this.AddErrorToTarget(validationError, false);
     this.RemoveErrorFromTarget(validationError1);
     if (!this.lastSourceUpdateThrewException && flag1)
     {
         this.RemoveNotifyDataErrorInfosFromTarget();
     }
     this.lastSourceUpdateThrewException = flag1;
     this.RaiseErrorNotifications();
 }