Skip to main content Skip to footer

How to implement input validation with FluentValidation and MVVMLite

When using a DataGrid with FluentValidation and the IDataErrorInfo interface, you may encounter an issue where error messages appear twice in the validation tooltip. This often happens because the grid is picking up error notifications from both the individual property validation and the object-level IDataErrorInfo.Error property, leading to redundant UI indicators and tooltips.

Solution
This behavior occurs by design when IDataErrorInfo.Error is populated, as it forces the DataGrid to display a row-level error indicator in addition to the cell-level validation. If you are already using FluentValidation to handle property-specific errors, you should ensure that the IDataErrorInfo.Error property returns null (or an empty string).

To show a summary of all errors in a separate column without triggering the duplicate tooltip, create a distinct, read-only property in your Model (e.g., DataError) that joins your validation messages. By keeping the standard Error property empty, you prevent the DataGrid from double-reporting the validation state while still maintaining the ability to display or bind to a full list of errors elsewhere in the row.

public class ProductValidator : AbstractValidator<Product>
{
    public ProductValidator()
    {
        RuleFor(x => x.Type).NotNull().WithMessage("Empty Value");
    }
}