Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

CustomMaskEventArgs.Cancel() Method

In This Article

Cancels the user action.

Namespace: DevExpress.Xpf.Editors

Assembly: DevExpress.Xpf.Core.v24.2.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