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 errorsGetErrors
method returns anIEnumerable
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
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 objectpublic string this[string columnName] { get; }
- get the error message for the property with the given name.
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.
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.
projects
ILSpy - IL code viewer plugin
Recently when I worked with ILSpy I wanted to see the Intermediate Language but I could not find this functionality. So I decided to create a plugin to ILSpy called ILViewer. You can find it on github: https://github.com/kmatyaszek/ILSpy-ILViewer.