A collection of ValidationRule objects that will be used to validate user input.
Example
All examples in this topic assume that the grid is bound to a list of Composer objects, unless stated otherwise.
The following example demonstrates how to create a custom ValidationRule and apply it to a column's binding to provide binding-level validation.Implementation of the YearValidationRule validation rule.Implementation of the YearValidationRule validation rule.
Imports System
Imports System.Windows.Controls
Imports System.Globalization
Namespace Xceed.Wpf.Documentation
PublicClass YearValidationRule
Inherits ValidationRule
PublicOverridesFunction Validate( ByVal value AsObject, _
ByVal cultureInfo As CultureInfo ) As ValidationResult
DimyearAsInteger = CInt( value )
Ifyear > DateTime.Now.Year ThenReturnNew ValidationResult( False, "Chosen year cannot be greater than this year." )
EndIfReturn ValidationResult.ValidResult
End FunctionEnd ClassEnd Namespace
using System;
using System.Windows.Controls;
using System.Globalization;
namespace Xceed.Wpf.Documentation
{
publicclass YearValidationRule : ValidationRule
{
publicoverride ValidationResult Validate( object value, CultureInfo cultureInfo )
{
int year = ( int )value;
if( year > DateTime.Now.Year )
returnnew ValidationResult( false, "Chosen year cannot be greater than this year." );
return ValidationResult.ValidResult;
}
}
}
Requirements
Target Platforms: Windows 11, Windows, 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2