wpf-devexpress-dot-xpf-dot-editors-dot-custommaskeventargs-244c1612.md
Cancels the user action.
Namespace : DevExpress.Xpf.Editors
Assembly : DevExpress.Xpf.Core.v25.2.dll
NuGet Package : DevExpress.Wpf.Core
public void Cancel()
Public Sub Cancel
You cannot call the Cancel method if the ActionType property returns Init.
The following code sample limits the maximum number of characters to 5:
void OnCustomMask(object sender, DevExpress.Xpf.Editors.CustomMaskEventArgs e) {
if (e.IsCanceled || e.ResultEditText.Length < e.CurrentEditText.Length ||
e.ActionType == CustomTextMaskInputAction.Init || e.ResultEditText.Length <= 5)
return;
if (e.CurrentEditText.Length == 5 && e.CurrentSelectedText == String.Empty) {
e.Cancel();
return;
}
var maxInsertLength = 5 - e.CurrentHead.Length - e.CurrentTail.Length;
e.SetResult(e.CurrentHead + e.InsertedText.Substring(0, maxInsertLength), e.CurrentTail);
}
Private Sub OnCustomMask(ByVal sender As Object, ByVal e As DevExpress.Xpf.Editors.CustomMaskEventArgs)
If e.IsCanceled OrElse e.ResultEditText.Length < e.CurrentEditText.Length OrElse e.ActionType = CustomTextMaskInputAction.Init OrElse e.ResultEditText.Length <= 5 Then Return
If e.CurrentEditText.Length = 5 AndAlso e.CurrentSelectedText = String.Empty Then
e.Cancel()
Return
End If
Dim maxInsertLength = 5 - e.CurrentHead.Length - e.CurrentTail.Length
e.SetResult(e.CurrentHead + e.InsertedText.Substring(0, maxInsertLength), e.CurrentTail)
End Sub
See Also