Back to Devexpress

CustomMaskEventArgs.SetResult(String, Int32, Nullable<Int32>) Method

wpf-devexpress-dot-xpf-dot-editors-dot-custommaskeventargs-dot-setresult-x28-system-dot-string-system-dot-int32-system-dot-nullable-system-dot-int32-x29.md

latest2.8 KB
Original Source

CustomMaskEventArgs.SetResult(String, Int32, Nullable<Int32>) Method

Sets the editor text, cursor position, and selection anchor.

Namespace : DevExpress.Xpf.Editors

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public void SetResult(
    string editText,
    int cursorPosition,
    int? selectionAnchor = null
)
vb
Public Sub SetResult(
    editText As String,
    cursorPosition As Integer,
    selectionAnchor As Integer? = Nothing
)

Parameters

NameTypeDescription
editTextString

The editor’s text.

| | cursorPosition | Int32 |

The cursor (caret) position.

|

Optional Parameters

NameTypeDefaultDescription
selectionAnchorNullable<Int32>null

The selection anchor.

|

Remarks

The following code sample allows users to enter only Latin letters and capitalizes entered characters:

csharp
void OnCustomMask(object sender, DevExpress.Xpf.Editors.CustomMaskEventArgs e) {
    if (e.ActionType == CustomTextMaskInputAction.Init || e.IsCanceled == true)
        return;
    var textInfo = CultureInfo.InvariantCulture.TextInfo;
    if (!Regex.IsMatch(e.InsertedText, @"^[a-zA-Z]+$") && e.ActionType == CustomTextMaskInputAction.Insert)
        e.Cancel();
    else e.SetResult(textInfo.ToUpper(e.ResultEditText), e.ResultCursorPosition);
}
vb
Private Sub OnCustomMask(ByVal sender As Object, ByVal e As DevExpress.Xpf.Editors.CustomMaskEventArgs)
    If e.ActionType = CustomTextMaskInputAction.Init OrElse e.IsCanceled = True Then Return
    Dim textInfo = CultureInfo.InvariantCulture.TextInfo

    If Not Regex.IsMatch(e.InsertedText, "^[a-zA-Z]+$") AndAlso e.ActionType = CustomTextMaskInputAction.Insert Then
        e.Cancel()
    Else
        e.SetResult(textInfo.ToUpper(e.ResultEditText), e.ResultCursorPosition)
    End If
End Sub

See Also

CustomMaskEventArgs Class

CustomMaskEventArgs Members

DevExpress.Xpf.Editors Namespace