コード例 #1
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();
 }
コード例 #2
0
 internal void BeginSetBinding()
 {
     this.updateState = BindingExpression.UpdateState.SettingUpBinding;
 }
コード例 #3
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;
 }
コード例 #4
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();
 }