Skip to main content
All docs
V24.1

CustomMaskEventArgs.Cancel() Method

Cancels the user action.

Namespace: DevExpress.Xpf.Editors

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

NuGet Package: DevExpress.Wpf.Core

Declaration

public void Cancel()

Remarks

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);
}
See Also