WPF Validation

WPF Validation - Using INotifyDataErrorInfo

In the .NET 4.5 was introduced new interface INotifyDataErrorInfo which enables data entity classes to implement custom validation rules and expose validation results asynchronously. This interface has three members:

  • HasErrors property indicates whether there are any validation errors
  • GetErrors method returns an IEnumerable that contains validation errors for the specified property (when the propertyName parameter isn’t equal to null or empty string) or for the entire entity (when the propertyName parameter is equal to null or empty string)
  • ErrorsChanged event must occur when the validation errors have changed for a property or for the entity
2 min read

WPF Validation - Using IDataErrorInfo

In this blog post, I will show you how you can validate data using IDataErrorInfo. This interface has only two members which need to be implemented:

  • public string Error { get; } - gets an error message indicating what is wrong with this object
  • public string this[string columnName] { get; } - get the error message for the property with the given name.
1 min read

WPF Validation - Display errors to the user

In this post, I will show how you can present user input validation errors to the user. By default, WPF shows a red border around the TextBox when the entered value is invalid. But in this case, our user has no idea what is wrong with entered data. We need to inform the user by providing an error message on the view.

3 min read

WPF Validation - Using ValidatesOnExceptions

In WPF we have few options to validate user input data. In this article, I will show you validation based on the exception. This validation is applied in very simple solutions. The only thing you should do is throw an exception on property level and set ValidatesOnExceptions to true in the view.

1 min read
Back to Top ↑

projects

Back to Top ↑