DocumentPreviewControl.ValidateEditingField Event
In This Article
Occurs before the editor invoked for the edit field is closed. Allows you to validate the edit field value.
Namespace: DevExpress.Xpf.Printing
Assembly: DevExpress.Xpf.Printing.v24.2.dll
NuGet Package: DevExpress.Wpf.Printing
#Declaration
#Event Data
The ValidateEditingField event's data class is EditingFieldValidationEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Editing |
Gets the edit field for which the event is raised.
Inherited from Editing |
Error |
Specifies the tooltip message. |
Error |
Specifies the type of the error icon displayed in the editor. |
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 Routed |
Is |
Specifies whether the edit field value is valid. |
Original |
Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.
Inherited from Routed |
Routed |
Gets or sets the Routed |
Source |
Gets or sets a reference to the object that raised the event.
Inherited from Routed |
Value | Gets the edit field value. |
The event data class exposes the following methods:
Method | Description |
---|---|
Invoke |
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 Routed |
On |
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 Routed |
#Remarks
The following code validates the value in the edit field’s Date Time Editor so that the user can enter only dates for the current month:
<Window x:Class="ValidateEditingFields_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ValidateEditingFields_MVVM"
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<Grid>
<dxp:DocumentPreviewControl RequestDocumentCreation="True"
DocumentSource="{Binding Report}"
HighlightEditingFields="True">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand Event="{x:Static dxp:DocumentPreviewControl.ValidateEditingFieldEvent}"
PassEventArgsToCommand="True"
Command="{Binding OnValidateEditingFieldCommand}" />
</dxmvvm:Interaction.Behaviors>
</dxp:DocumentPreviewControl>
</Grid>
</Window>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Xpf.Printing;
using DevExpress.XtraReports.UI;
using System;
namespace ValidateEditingFields_MVVM {
public class ViewModel : ViewModelBase {
public XtraReport Report { get; }
public ViewModel() {
Report = new XtraReport1();
}
[Command]
public void OnValidateEditingField(EditingFieldValidationEventArgs args) {
if(args.EditingField.ID == "DateField")
ValidateDateTimeEditingField(args);
}
void ValidateDateTimeEditingField(EditingFieldValidationEventArgs args) {
DateTime value = default(DateTime);
try {
value = Convert.ToDateTime(args.Value);
} catch (Exception e) {
args.IsValid = false;
args.ErrorMessage = e.Message;
args.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical;
}
DateTime now = DateTime.Now;
args.IsValid = value.Year == now.Year && value.Month == now.Month;
}
}
}
See Also