WPF Validation Manually Adding Errors into Validation.Errors Collection

前端 未结 2 1443
别那么骄傲
别那么骄傲 2021-02-13 17:25

Is there any way to manually/dynamically add errors to the Validation.Errors collection?

2条回答
  •  情歌与酒
    2021-02-13 17:44

    from http://www.wpftutorial.net/ValidationErrorByCode.html

    ValidationError validationError = new ValidationError(regexValidationRule, 
        textBox.GetBindingExpression(TextBox.TextProperty));
    
    validationError.ErrorContent = "This is not a valid e-mail address";
    
    Validation.MarkInvalid(
        textBox.GetBindingExpression(TextBox.TextProperty), 
        validationError);
    

提交回复
热议问题