Skip to main content
All docs
V23.2

RepositoryItemTextEdit.MaskSettings Property

Provides access to settings that allow you to create input masks. This property replaces the Mask property beginning with v20.2. See the following help topic for more information: Input Masks.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v23.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Format")]
public virtual MaskSettings MaskSettings { get; }

Property Value

Type
DevExpress.XtraEditors.Mask.MaskSettings

Remarks

The MaskSettings property allows you to set up input masks at design time and in code.

At Design Time

In the Visual Studio Property Grid, click the ellipsis button next to the MaskSettings property. In the “Mask Settings” dialog that pops up, select the required mask type and choose any of the predefined expressions.

Mask Settings Dialog

If there is no ready-to-use expression that fits your needs, click “Create New Mask…” and combine metacharacters to create a custom expression.

Custom RegEx mask

To specify additional mask settings, tick the corresponding checkbox at the bottom left corner of a dialog. Available settings depend on the active mask type.

In Code

To set up a mask expression and configure mask settings in code, use the MaskSettings.Configure method. This method requires that you specify one of the following types defined in the DevExpress.Data.Mask.Internal namespace:

  • MaskSettings.Numeric
  • MaskSettings.DateTime
  • MaskSettings.DateTimeOffset
  • MaskSettings.TimeSpan
  • MaskSettings.Simple
  • MaskSettings.Regular
  • MaskSettings.RegExp

For example, the following code applies a numeric mask that allows users to enter decimal numbers in the “000.00” format, and specifies two additional settings: hides zeros that do not affect the value (“0.9” instead of “0.9”), and shows a decimal separator even when the fractional part is 0 (“110.” instead of “110”).

using DevExpress.XtraEditors.Mask;

//Fluent API
textEdit5.Properties.MaskSettings.Configure<MaskSettings.Numeric>(settings => {
    settings.MaskExpression = "##0.##";
    settings.AutoHideDecimalSeparator = false;
    settings.HideInsignificantZeros = true;
});

//regular API
var settings = textEdit5.Properties.MaskSettings.Configure<MaskSettings.Numeric>();
settings.MaskExpression = "##0.##";
settings.AutoHideDecimalSeparator = false;
settings.HideInsignificantZeros = true;

At the Data Source Layer

If your editor is bound to a field of a code-first data source, you have a third option to apply input masks: decorate data class properties with “…EditMask” attributes. An editor bound to this field applies a mask of the required type, and sets up additional options you specified as attribute parameters.

For example, the following code applies two masks:

  • a RegEx type mask that accepts any number of literals and automatically capitalizes the first character. The AllowBlankInput parameter allows users to leave this editor empty, and the disabled ShowPlaceholders hides placeholders.
  • a DateTime type mask that displays dates in the short “MM/DD/YYYY” format.
public class Employee {
    [RegExEditMask("[A-Z][a-z]+", AllowBlankInput = true, ShowPlaceholders = false)]
    public string FirstName { get; set; }
    [EditMask("d")]
    public DateTime HiredAt { get; set; }
}

The list below enumerates available data attributes. All attributes are declared in the System.ComponentModel.DataAnnotations namespace and stored in the DevExpress.Data assembly.

  • NumericEditMask
  • DateTimeEditMask
  • DateTimeOffsetEditMask
  • TimeSpanEditMask
  • SimpleEditMask
  • RegularEditMask
  • RegExEditMask

The EditMask attribute can be used instead of any of these attributes. It exposes only basic mask settings, and applies a mask type that fits the type of a property. For example, in the code sample above the attribute applies the DateTime mask because the “HiredAt” property is of the DateTime type.

See Also