Skip to main content

BaseEdit.Validate Event

Enables you to validate the editor’s value.

Namespace: DevExpress.Xpf.Editors

Assembly: DevExpress.Xpf.Core.v24.1.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

public event ValidateEventHandler Validate

Event Data

The Validate event's data class is ValidationEventArgs. The following properties provide information specific to this event:

Property Description
Culture Gets the culture related to the validation.
ErrorContent Gets or sets an object that describes the validation error.
ErrorType Gets or sets the error icon type.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
IsValid Gets or sets a value specifying whether the value is valid.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
UpdateSource Gets the action that caused the validation.
Value Gets the editor’s value.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.
SetError(Object, ErrorType) Marks the processed input value as invalid and displays an error within the editor with the specified error icon type.
SetError(Object) Marks the processed input value as invalid and displays an error within the editor.

Remarks

Handle the Validate event to manually validate the editor (e.g. to limit the range of valid values, implement a custom conditional validation mechanism, etc).

To specify when the editor should automatically validate its value, use the BaseEdit.ValidateOnEnterKeyPressed and BaseEdit.ValidateOnTextInput properties. To manually force the editor’s validation, call the BaseEdit.DoValidate method.

Note

The Validate event is not raised if the editor’s BaseEdit.CausesValidation property is set to false.

To learn more, see Input Validation.

Example

The following example shows how to handle the BaseEdit.Validate event to implement a custom validation procedure.

The image below shows the result:

exDataValidation

<dxe:TextEdit x:Name="dxTextEdit"
          ValidateOnTextInput="False"
          Validate="dxTextEdit_Validate"/>
private void dxTextEdit_Validate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e) {
    // e.Value - the processed input value
    if (e.Value == null) return;
    if (e.Value.ToString().Length > 4) return;
    // Set the e.IsValid property to 'false' if the input value is invalid
    e.IsValid = false;
    // Specifies the error icon type
    e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information;
    // Specifies the error text
    e.ErrorContent = "User ID is less than five symbols. Please correct.";
}
See Also