/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void UIStaff_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) hasError = true; else if (e.Action == ValidationErrorEventAction.Removed) hasError = false; }
/// <summary> /// 使用数据验证后,对数据进行验证 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private static void validationError(object sender, ValidationErrorEventArgs args) { if ((sender as FrameworkElement).DataContext != null && (sender as FrameworkElement).DataContext as IDataValidationInfo != null) { IDataValidationInfo dataValition = (sender as FrameworkElement).DataContext as IDataValidationInfo; bool isSuccess = (bool)((args.OriginalSource as FrameworkElement).GetValue(Validation.HasErrorProperty)); Binding bind = ((System.Windows.Data.BindingExpression)((System.Windows.Controls.ValidationError)args.Error).BindingInError).ParentBinding; if (bind != null) { string propetyName; if (bind.Source != null) { propetyName = bind.Path.Path + "@" + bind.Source.GetHashCode(); } else { propetyName = bind.Path.Path + "@" + (sender as FrameworkElement).DataContext.GetHashCode(); } if (isSuccess && args.Action == ValidationErrorEventAction.Added) { dataValition.Added(propetyName, args.Error.ErrorContent); } else if (!isSuccess && args.Action == ValidationErrorEventAction.Removed) { dataValition.Removed(propetyName); } } } }
/// <summary> /// プレゼン用 テキストボックスのバリデーションエラーを捕まえることができる /// </summary> /// <param name="sender">送信オブジェクト</param> /// <param name="e">バリデーションエラーに関するパラメータ</param> private void OnValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { // バリデーションエラーが発生したときの処理を追加できます } }
private void PhoneApplicationPage_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { MessageBox.Show(e.Error.Exception.Message, "Error", MessageBoxButton.OK); } }
private void grdConfig_ValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) _validationErrors.Add(e.Error); else _validationErrors.Remove(e.Error); btSave.IsEnabled = _validationErrors.Count == 0; }
private void ValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { MessageBox.Show(e.Error.ErrorContent.ToString()); } }
public void EntityValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) EntityErrorCount++; else if (EntityErrorCount > 0) EntityErrorCount--; }
private void Validation_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) _errors++; else _errors--; }
private void Validation_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) _noOfErrorsOnScreen++; else _noOfErrorsOnScreen--; }
public static void CheckEntityListError(ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) EntityListErrorCount++; else if (EntityListErrorCount > 0) EntityListErrorCount--; }
/// <summary> /// Shows the errors in a message box if any /// </summary> private void ControlsPanel_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { hasErrors = true; MessageBox.Show(e.Error.ErrorContent.ToString()); } }
private void Validation_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) errorCount++; if (e.Action == ValidationErrorEventAction.Removed) errorCount--; if (this.ok != null) this.ok.IsEnabled = (errorCount == 0); }
private void SurNameTextBox_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { System.Console.Beep(); MessageBox.Show(e.Error.ErrorContent.ToString()); } else System.Diagnostics.Trace.WriteLine("Validation error cleared"); }
private void txt_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { ((Control)sender).ToolTip = e.Error.ErrorContent.ToString(); } else { ((Control)sender).ToolTip = ""; } }
private void TextBox_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { _errors++; } else { _errors--; } }
private void Element_ValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added && !_errorMessages.Contains(e.Error.ErrorContent.ToString())) { _errorMessages.Add(e.Error.ErrorContent.ToString()); } else if (e.Action == ValidationErrorEventAction.Removed && _errorMessages.Contains(e.Error.ErrorContent.ToString())) { _errorMessages.Remove(e.Error.ErrorContent.ToString()); } }
/// <summary> /// Handle when data in the distance text box has error /// </summary> private void txtDistance_DataError(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { dataNoError = false; } else { dataNoError = true; } }
private void TextBox_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { userNameTextBox.Background = new SolidColorBrush(Colors.Red); } else if (e.Action == ValidationErrorEventAction.Removed) { userNameTextBox.Background = new SolidColorBrush(Colors.White); } }
void MainPage_BindingValidationError(object sender, ValidationErrorEventArgs e) { // If the app is running outside of the debugger then report the exception using a ChildWindow control. if (!System.Diagnostics.Debugger.IsAttached) { // NOTE: This will allow the application to continue running after an exception has been thrown but not handled. // For production applications this error handling should be replaced with something that will report the error to the website and stop the application. e.Handled = true; ErrorWindow.CreateNew(e.ToString()); } }
private void ScopeElement_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Removed) { Errors.Remove(e.Error); } else if (e.Action == ValidationErrorEventAction.Added) { Errors.Add(e.Error); } }
private void txtEmail_Error(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { _noOfErrorsOnScreen++; } else { _noOfErrorsOnScreen--; } }
private void Window_Error(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { errorMessages.Add(e.Error.Exception.Message); } else { errorMessages.Remove(e.Error.Exception.Message); } Addbutton.IsEnabled = !errorMessages.Any(); }
private void Validation_Error(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) _errors++; else _errors--; if (_errors == 0) btn_actualizar.IsEnabled = true; else btn_actualizar.IsEnabled = false; }
private void ContentPanel_BindingValidationError(object sender, ValidationErrorEventArgs e) { TextBox temp = (TextBox)sender; if (e.Action == ValidationErrorEventAction.Added) { temp.Background = new SolidColorBrush(Colors.Red); } else { temp.Background = new SolidColorBrush(Colors.White); } }
private void ExceptionValidationErrorHandler(object sender, RoutedEventArgs e) { System.Windows.Controls.ValidationErrorEventArgs args = (System.Windows.Controls.ValidationErrorEventArgs)e; if (args.Error.RuleInError is System.Windows.Controls.ExceptionValidationRule) { ViewModelBase _viewModelBase = this.DataContext as ViewModelBase; if (_viewModelBase != null) { //we only want to work with validation errors that are Exceptions because the business object has already recorded the business rule violations using IDataErrorInfo. BindingExpression bindingExpression = (System.Windows.Data.BindingExpression)args.Error.BindingInError; string dataItemName = bindingExpression.DataItem.ToString(); string propertyPath = bindingExpression.ParentBinding.Path.Path; System.Text.StringBuilder sb = new System.Text.StringBuilder(1024); foreach (ValidationError validationError in System.Windows.Controls.Validation.GetErrors((DependencyObject)args.OriginalSource)) { if (validationError.RuleInError is System.Windows.Controls.ExceptionValidationRule) { sb.AppendFormat("{0} has error ", propertyPath); if (validationError.Exception == null || validationError.Exception.InnerException == null) { sb.AppendLine(validationError.ErrorContent.ToString()); } else { sb.AppendLine(validationError.Exception.InnerException.Message); } } } if (args.Action == ValidationErrorEventAction.Added) { _viewModelBase.AddUIValidationError(new UIValidationError(dataItemName, propertyPath, sb.ToString())); } else if (args.Action == ValidationErrorEventAction.Removed) { _viewModelBase.RemoveUIValidationError(new UIValidationError(dataItemName, propertyPath, sb.ToString())); } else { //this can only happen if the .NET Framework changes. Better to put a sanity check in now that have a very hard to find bug later. throw new ArgumentOutOfRangeException("Action", args.Action, "Action value was not programmed."); } } } }
// Based on exception handler from Josh Smith blog. public void Handler(object sender, RoutedEventArgs e) { System.Windows.Controls.ValidationErrorEventArgs args = e as System.Windows.Controls.ValidationErrorEventArgs; if (args.Error.RuleInError is System.Windows.Controls.ValidationRule) { if (ErrorContainer != null) { Tracer.LogValidation("ViewBase.Handler called for ValidationRule exception."); // Only want to work with validation errors that are Exceptions because the business object has already recorded the business rule violations using IDataErrorInfo. BindingExpression bindingExpression = args.Error.BindingInError as System.Windows.Data.BindingExpression; Debug.Assert(bindingExpression != null); string propertyName = bindingExpression.ParentBinding.Path.Path; DependencyObject OriginalSource = args.OriginalSource as DependencyObject; // Construct the error message. string errorMessage = ""; ReadOnlyObservableCollection <System.Windows.Controls.ValidationError> errors = System.Windows.Controls.Validation.GetErrors(OriginalSource); if (errors.Count > 0) { StringBuilder builder = new StringBuilder(); builder.Append(propertyName).Append(":"); System.Windows.Controls.ValidationError error = errors[errors.Count - 1]; { if (error.Exception == null || error.Exception.InnerException == null) { builder.Append(error.ErrorContent.ToString()); } else { builder.Append(error.Exception.InnerException.Message); } } errorMessage = builder.ToString(); } // Add or remove the validation error to the validation error collection. Debug.Assert(args.Action == ValidationErrorEventAction.Added || args.Action == ValidationErrorEventAction.Removed); StringBuilder errorID = new StringBuilder(); errorID.Append(args.Error.RuleInError.ToString()); if (args.Action == ValidationErrorEventAction.Added) { ErrorContainer.AddError(new ValidationToolkit.ValidationError(propertyName, errorID.ToString(), errorMessage)); } else if (args.Action == ValidationErrorEventAction.Removed) { ErrorContainer.RemoveError(propertyName, errorID.ToString()); } } } }
private void ErrorChangedHandler(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { errors.Add(e.Error); } else { errors.Remove(e.Error); } ViewModel.IsValid = !errors.Any(); }
private void LayoutRoot_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { if(e.OriginalSource is TextBox) (e.OriginalSource as TextBox).Background = new SolidColorBrush(Colors.Red); } else if (e.Action == ValidationErrorEventAction.Removed) { if (e.OriginalSource is TextBox) (e.OriginalSource as TextBox).Background = new SolidColorBrush(Colors.White); } }
private void AMOUNT_Error(object sender, ValidationErrorEventArgs e) { BindingExpression bx = (BindingExpression)e.Error.BindingInError; if (bx.HasValidationError) { PLUS.Visibility = Visibility.Hidden; MINUS.Visibility = Visibility.Hidden; } else { PLUS.Visibility = Visibility.Visible; MINUS.Visibility = Visibility.Visible; } }
private void Grid_Error(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { var control = (Control)e.OriginalSource; //Added - если ошибка ПРОИЗОШЛА if (e.Action == ValidationErrorEventAction.Added) { control.ToolTip = e.Error.ErrorContent.ToString(); } else { control.ToolTip = ""; } }
private void ErrorChangedHandler(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { AddError(e.OriginalSource, e.Error); } else { Tuple<object, ValidationError> error = errors.FirstOrDefault(err => err.Item1 == e.OriginalSource && err.Item2 == e.Error); if (error != null) { errors.Remove(error); } } ValidationHelper.InternalSetIsValid(owner, !errors.Any()); }
private void BindingValidationError(object sender, ValidationErrorEventArgs e) { var tb = sender as TextBox; if (e.Action == ValidationErrorEventAction.Added) { // new errors occured tb.Foreground = new SolidColorBrush(Colors.Red); } else { // error fixed tb.ClearValue(TextBox.ForegroundProperty); } }
void ErrorHandler(object sender, ValidationErrorEventArgs args) { if (!(args.Error.RuleInError is DataErrorValidationRule)) { if (args.Action == ValidationErrorEventAction.Added) bindingExceptions.Add(args.Error); else bindingExceptions.Remove(args.Error); } if (!LetErrorsBubble) args.Handled = true; OnBindingExceptionChanged(); }
static void OnValidationError(DependencyObject source, ValidationError validationError, ValidationErrorEventAction action) { ValidationErrorEventArgs args = new ValidationErrorEventArgs(validationError, action); if (source is ContentElement) { ((ContentElement)source).RaiseEvent(args); } else if (source is UIElement) { ((UIElement)source).RaiseEvent(args); } else if (source is UIElement3D) { ((UIElement3D)source).RaiseEvent(args); } }
private void ValidationErrorEventHandler(object sender, ValidationErrorEventArgs e) { if (e.Error.BindingInError is BindingExpression) { if (e.Error.BindingInError == BindingOperations.GetBindingExpression(this, DateRangeUC.FromDateProperty)) { this.mdpDateFrom.BindingGroup.ValidationRules.Clear(); this.mdpDateFrom.BindingGroup.ValidationRules.Add(new BubbleErrorValidationRule(e.Error)); this.mdpDateFrom.BindingGroup.ValidateWithoutUpdate(); } else if (e.Error.BindingInError == BindingOperations.GetBindingExpression(this, DateRangeUC.TillDateProperty)) { this.mdpDateTo.BindingGroup.ValidationRules.Clear(); this.mdpDateTo.BindingGroup.ValidationRules.Add(new BubbleErrorValidationRule(e.Error)); this.mdpDateTo.BindingGroup.ValidateWithoutUpdate(); } } }
/// <summary> /// Event handler for target control's BindingValidationError event. /// </summary> /// <param name="sender">The target that had a BindingValidationError event.</param> /// <param name="e">The ValidationErrorEventArgs for this event.</param> private void Target_BindingValidationError(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { if (!this._errors.Contains(e.Error)) { this._errors.Add(e.Error); } } else if (e.Action == ValidationErrorEventAction.Removed) { if (this._errors.Contains(e.Error)) { this._errors.Remove(e.Error); } } this.ParseTargetValidState(); }
private void ErrorChangedHandler(object sender, ValidationErrorEventArgs e) { if (e.Action == ValidationErrorEventAction.Added) { errors.Add(new Tuple<object, ValidationError>(e.OriginalSource, e.Error)); if (e.OriginalSource is FrameworkElement) ((FrameworkElement) e.OriginalSource).Unloaded += ValidationSourceUnloaded; else if (e.OriginalSource is FrameworkContentElement) ((FrameworkContentElement) e.OriginalSource).Unloaded += ValidationSourceUnloaded; } else { Tuple<object, ValidationError> error = errors.FirstOrDefault(err => err.Item1 == e.OriginalSource && err.Item2 == e.Error); if (error != null) { errors.Remove(error); } } ViewModel.IsValid = !errors.Any(); }
// Token: 0x06005983 RID: 22915 RVA: 0x0018B3E4 File Offset: 0x001895E4 private static void OnValidationError(DependencyObject source, ValidationError validationError, ValidationErrorEventAction action) { ValidationErrorEventArgs e = new ValidationErrorEventArgs(validationError, action); if (source is ContentElement) { ((ContentElement)source).RaiseEvent(e); return; } if (source is UIElement) { ((UIElement)source).RaiseEvent(e); return; } if (source is UIElement3D) { ((UIElement3D)source).RaiseEvent(e); } }
private void TextBox_Error(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { switch (e.Action) { case ValidationErrorEventAction.Added: _ErrorCount++; break; case ValidationErrorEventAction.Removed: _ErrorCount--; break; default: break; } if (_ErrorCount == 0) { ApplyBtn.IsEnabled = true; } else { ApplyBtn.IsEnabled = false; } }
private void OnValidationError(object sender, ValidationErrorEventArgs e) { //if (e.Action == ValidationErrorEventAction.Added) //{ // MessageLabel.Content = e.Error.ErrorContent.ToString(); //} }
/// <summary> /// Event handler for target control's BindingValidationError event. /// </summary> /// <param name="sender">The sender of the BindingValidationError event.</param> /// <param name="e">The ValidationErrorEventArgs for this event.</param> private void Target_BindingValidationError(object sender, ValidationErrorEventArgs e) { this.ParseTargetValidState(); }
private void idInput_ValidationError(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { saveButton.IsEnabled = e.Action != System.Windows.Controls.ValidationErrorEventAction.Added; }
private void TextBox_Error(object sender, System.Windows.Controls.ValidationErrorEventArgs e) { ((Control)sender).ToolTip = e.Action == ValidationErrorEventAction.Added ? e.Error.ErrorContent.ToString() : ""; }