TextEdit.CustomMask Event
Occurs after the editor is initialized, got the focus, or the editor’s value is changed.
Namespace: DevExpress.Xpf.Editors
Assembly: DevExpress.Xpf.Core.v24.2.dll
NuGet Package: DevExpress.Wpf.Core
#Declaration
public event EventHandler<CustomMaskEventArgs> CustomMask
#Event Data
The CustomMask event's data class is CustomMaskEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Action |
Gets the user action. |
Current |
Gets the cursor (caret) position before a user performs an action. |
Current |
Gets text displayed in the editor before a user performs an action. |
Current |
Gets the editor’s text that precedes the cursor (caret) position or selected text. |
Current |
Gets the editor’s selected text. |
Current |
Gets the selection start point before a user performs an action. |
Current |
Gets the position of the right-most selected character. |
Current |
Gets the position of the left-most selected character. |
Current |
Gets the editor’s text that follows the cursor (caret) position or selected text. |
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 |
Inserted |
Gets text a user attempts to add to the editor. |
Is |
Gets whether the user action does not lead to the editor value change. |
Is |
Gets whether the editor contains selected text. |
Original |
Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.
Inherited from Routed |
Result |
Gets the cursor (caret) position after a user performs an action. |
Result |
Gets text displayed in the editor after a user performs an action. |
Result |
Gets the selection start point after a user performs an action. |
Routed |
Gets or sets the Routed |
Source |
Gets or sets a reference to the object that raised the event.
Inherited from Routed |
Tag | Gets the editor’s Tag property value. |
The event data class exposes the following methods:
Method | Description |
---|---|
Cancel() | Cancels the user action. |
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 |
Set |
Sets the editor text, cursor position, and selection anchor. |
Set |
Sets the editor text and cursor position. |
To |
Gets the transcript of the user’s action in the following format: (Initial .
|
#Remarks
You can use custom masks to process user input and specify complex custom conditions. Do the following to specify a custom mask:
- Set the editor’s MaskType property to
Custom
. - Handle the
CustomMask
event. - Process the text displayed in the editor (e.CurrentEditText), the text entered by a user (e.InsertedText), or the edited text (e.ResultEditText).
- Use e.SetResult or e.Cancel methods to specify the editor’s final text.
The following code sample allows users to enter only valid image file names:
void OnCustomMask(object sender, DevExpress.Xpf.Editors.CustomMaskEventArgs e) {
var imageExtensions = new string[] {".jpeg", ".jpg", ".png", ".gif", ".tiff", ".tif", ".bmp", ".svg", ".esp"};
var enteredExtension = Path.GetExtension(e.ResultEditText);
if (e.ResultEditText.Any(x => Path.GetInvalidFileNameChars().Contains(x)))
e.Cancel();
if (!imageExtensions.Any(x => x.StartsWith(enteredExtension, System.StringComparison.OrdinalIgnoreCase)))
e.Cancel();
}
Refer to the following help topic for more information: Mask Type: Custom.