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;
}
}
}