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
Event Data
The CustomMask event's data class is CustomMaskEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
ActionType | Gets the user action. |
CurrentCursorPosition | Gets the cursor (caret) position before a user performs an action. |
CurrentEditText | Gets text displayed in the editor before a user performs an action. |
CurrentHead | Gets the editor’s text that precedes the cursor (caret) position or selected text. |
CurrentSelectedText | Gets the editor’s selected text. |
CurrentSelectionAnchor | Gets the selection start point before a user performs an action. |
CurrentSelectionEnd | Gets the position of the right-most selected character. |
CurrentSelectionStart | Gets the position of the left-most selected character. |
CurrentTail | 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 RoutedEventArgs. |
InsertedText | Gets text a user attempts to add to the editor. |
IsCanceled | Gets whether the user action does not lead to the editor value change. |
IsSelection | Gets whether the editor contains selected text. |
OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
ResultCursorPosition | Gets the cursor (caret) position after a user performs an action. |
ResultEditText | Gets text displayed in the editor after a user performs an action. |
ResultSelectionAnchor | Gets the selection start point after a user performs an action. |
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. |
Tag | Gets the editor’s Tag property value. |
The event data class exposes the following methods:
Method | Description |
---|---|
Cancel() | Cancels the user action. |
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. |
SetResult(String, Int32, Nullable<Int32>) | Sets the editor text, cursor position, and selection anchor. |
SetResult(String, String) | Sets the editor text and cursor position. |
ToString() |
Gets the transcript of the user’s action in the following format: (InitialState)->UserAction->(FinalState) .
|
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:
<dxe:TextEdit MaskType="Custom" CustomMask="OnCustomMask"/>
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.