Skip to main content
.NET Framework Class Library
ValidateValueCallback Delegate

Represents a method used as a callback that validates the effective value of a dependency property.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
Public Delegate Function ValidateValueCallback ( _
	value As [%$TOPIC/ms590088_en-us_VS_110_1_0_0_0_0%] _
) As [%$TOPIC/ms590088_en-us_VS_110_1_0_0_0_1%]
public delegate [%$TOPIC/ms590088_en-us_VS_110_1_0_1_0_0%] ValidateValueCallback(
	[%$TOPIC/ms590088_en-us_VS_110_1_0_1_0_1%] value
public delegate [%$TOPIC/ms590088_en-us_VS_110_1_0_2_0_0%] ValidateValueCallback(
	[%$TOPIC/ms590088_en-us_VS_110_1_0_2_0_1%]^ value
type ValidateValueCallback = 
    delegate of  
        value:[%$TOPIC/ms590088_en-us_VS_110_1_0_3_0_0%] -> [%$TOPIC/ms590088_en-us_VS_110_1_0_3_0_1%]
JScript does not support delegates.


Type: SystemObject

The value to be validated.

Return Value

Type: SystemBoolean
true if the value was validated; false if the submitted value was invalid.

Callbacks based on this delegate are used by certain signatures of DependencyPropertyRegister and related methods, such as RegisterAttached and read-only equivalents. You should use signatures that take the validateValueCallback parameter if you want specific validation of the property value each time that its effective is set. You should then implement this callback such that it performs the actual validation of the proposed value. The callback should return true if the value submitted to the callback is valid, and false otherwise. A false value will produce an exception in the specific portion of the property system where the invalid property set was attempted, so your application should be prepared to handle these exceptions.

Validation callbacks are stored on dependency property identifiers, rather than dependency property metadata. Your validation callback does not have access to a specific instance of a DependencyObject on which the property is set, and can only influence what values are accepted for the property in general. If you need a callback that can change property values based on a specific instance, you should use a combination of a CoerceValueCallback and PropertyChangedCallback callbacks as applied to the property metadata of your property. You might also apply these callbacks to related properties that should influence your property's value. For details, see Dependency Property Callbacks and Validation.


The following example includes an implementation of this callback to validate a range of values for a custom dependency property. In this case the property value expects an enumeration, and the validation assures that the provided value evaluates to a member of that enumeration.

		Private Shared Function ShirtValidateCallback(ByVal value As Object) As Boolean
			Dim sh As ShirtTypes = CType(value, ShirtTypes)
			Return (sh=ShirtTypes.None OrElse sh = ShirtTypes.Bowling OrElse sh = ShirtTypes.Dress OrElse sh = ShirtTypes.Rugby OrElse sh = ShirtTypes.Tee)

		End Function
private static bool ShirtValidateCallback(object value)
			ShirtTypes sh = (ShirtTypes) value;
			return (sh==ShirtTypes.None || sh == ShirtTypes.Bowling || sh == ShirtTypes.Dress || sh == ShirtTypes.Rugby || sh == ShirtTypes.Tee);

Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1