private void SetSearchInlineError(bool isInvalid, string message = "") { var bindingExpressionBase = ValueTextBox?.GetBindingExpression(TextBox.TextProperty); if (bindingExpressionBase == null) { return; } if (isInvalid) { var validationError = new ValidationError(new ExceptionValidationRule(), bindingExpressionBase) { ErrorContent = message }; Validation.MarkInvalid(bindingExpressionBase, validationError); } else { Validation.ClearInvalid(bindingExpressionBase); } }
private void baseNodeControl_Loaded(object sender, RoutedEventArgs e) { var bindExp = ValueTextBox.GetBindingExpression(TextBox.TextProperty); if (bindExp != null) { if (bindExp.ParentBinding.ValidationRules.Count > 0) { var rule = bindExp.ParentBinding.ValidationRules[0] as InputWindow.RequiredRule; if (rule != null) { rule.OnValidateCheck = (object value, CultureInfo cultureInfo) => { var param = CSParam as CommonValueConstructionParams; if (param == null) { return(new ValidationResult(false, "参数类型不合法")); } try { System.Convert.ChangeType(value, param.ValueType); return(ValidationResult.ValidResult); } catch (System.Exception) { return(new ValidationResult(false, "数值不合法")); } } } ; } } } }