Wpf textbox validating
The thin red line doesn't convey enough information to the user, and is more detrimental than beneficial.At a minimum, the tool tip for the control needs to be set to the error text, and a more visual indicator that there is an issue.It may sound like a good idea at first, but you don't want your user to keep guessing why the button does not work and what they may be missing. You can leave OK/Save disabled until all fields validate successfully, but a better approach (in cases where most/all fields start out blank and a user might forget to fill in one that's required) is to have the button enabled, but to validate all blank fields when it's clicked and only close if they pass, putting up the highlight on those that fail as normal.It's ok to disable the button after initial submit and while the errors are shown (assumption that field validation happens on "keyup" so as soon as the last field passes validation - the button reactivates instantly). This way, you don't have the problem of displaying an irritating highlight on fields the user hasn't gotten to.I've seen a lot of websites where field labels / notes ask for one thing but validation is very limited.
The indexer accepts a property name and returns the error detail. To have the WPF Window display an error condition simply add the Validates On Data Errors=true attribute to the binding.
Look this tutorial for validation rules: The error message is inside the tooltip, but you can put the error message in a storyboard and animate it. Alternatively, of course, leave the OK button disabled until all required fields are valid and non-blank, but only put up the validation highlight/tooltip once they've been focused at least once.
Silently correcting user input is not a best practice in most cases, as it tends to keep users from correctly entering what they wanted.
To do this, we are going to create a style that replaces the default error template.
The sample here only applies to Text Boxes, but can be simply extended for other controls.