menu

WinUI

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class SfMaskedTextBox - WinUI API Reference | Syncfusion

    Show / Hide Table of Contents

    Class SfMaskedTextBox

    The SfMaskedTextBox control is an enhanced version of a text box that additionally restricts input to conform to a specific structure or mask.

    Inheritance
    System.Object
    SfMaskedTextBox
    Namespace: Syncfusion.UI.Xaml.Editors
    Assembly: Syncfusion.Editors.WinUI.dll
    Syntax
    public class SfMaskedTextBox : Control
    Examples

    This example illustrates how to set email mask value using regex mask.

    <syncfusion:SfMaskedTextBox Header="Email Input" MaskType="RegEx" Mask="[A-Za-z0-9-.%]+@[A-Za-z0-9]+.[A-Za-z]{3}"/>
    SfMaskedTextBox maskedTextBox = new SfMaskedTextBox();
    maskedTextBox.MaskType = MaskedTextBoxMaskType.RegEx;
    maskedTextBox.Mask = "[A-Za-z0-9-.%]+@[A-Za-z0-9]+.[A-Za-z]{3}";
    maskedTextBox.Header = "Email Input";

    Constructors

    SfMaskedTextBox()

    Initializes the new instance of the class.

    Declaration
    public SfMaskedTextBox()

    Fields

    CultureProperty

    Identifies the Culture dependency property.

    Declaration
    public static readonly DependencyProperty CultureProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Culture dependency property.

    CustomErrorBorderBrushProperty

    Identifies CustomErrorBorderBrush dependency property.

    Declaration
    public static readonly DependencyProperty CustomErrorBorderBrushProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the CustomErrorBorderBrush dependency property.

    CustomErrorIconProperty

    Identifies CustomErrorIcon dependency property.

    Declaration
    public static readonly DependencyProperty CustomErrorIconProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the CustomErrorIcon dependency property.

    DescriptionProperty

    Identifies the Description dependency property.

    Declaration
    public static readonly DependencyProperty DescriptionProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Description dependency property.

    ErrorContentProperty

    Identifies the ErrorContent dependency property.

    Declaration
    public static readonly DependencyProperty ErrorContentProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ErrorContent dependency property.

    ErrorContentTemplateProperty

    Identifies ErrorContentTemplate dependency property.

    Declaration
    public static readonly DependencyProperty ErrorContentTemplateProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ErrorContentTemplate dependency property.

    ErrorTypeProperty

    Identifies the ErrorType dependency property.

    Declaration
    public static readonly DependencyProperty ErrorTypeProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ErrorType dependency property.

    HeaderProperty

    Identifies the Header dependency property.

    Declaration
    public static readonly DependencyProperty HeaderProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Header dependency property.

    HeaderTemplateProperty

    Identifies the HeaderTemplate dependency property.

    Declaration
    public static readonly DependencyProperty HeaderTemplateProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the HeaderTemplate dependency property.

    MaskProperty

    Identifies the Mask dependency property.

    Declaration
    public static readonly DependencyProperty MaskProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Mask dependency property.

    MaskTypeProperty

    Identifies the MaskType dependency property.

    Declaration
    public static readonly DependencyProperty MaskTypeProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the MaskType dependency property.

    PromptCharProperty

    Identifies the PromptChar dependency property.

    Declaration
    public static readonly DependencyProperty PromptCharProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the PromptChar dependency property.

    TextProperty

    Identifies the Text dependency property.

    Declaration
    public static readonly DependencyProperty TextProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Text dependency property.

    ValueMaskFormatProperty

    Identifies the ValueMaskFormat dependency property.

    Declaration
    public static readonly DependencyProperty ValueMaskFormatProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ValueMaskFormat dependency property.

    ValueProperty

    Identifies the Value dependency property.

    Declaration
    public static readonly DependencyProperty ValueProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Value dependency property.

    Properties

    Culture

    Gets or sets the culture for mask values based on the given Culture.

    Declaration
    public CultureInfo Culture { get; set; }
    Property Value
    Type Description
    System.Globalization.CultureInfo

    It takes the culture value. The default value is System.Globalization.CultureInfo.CurrentCulture.

    CustomErrorBorderBrush

    Gets or sets the error border brush for the custom icon.

    Declaration
    public SolidColorBrush CustomErrorBorderBrush { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.Media.SolidColorBrush

    An Microsoft.UI.Xaml.Media.SolidColorBrush representing the custom error border brush displayed in the Syncfusion.UI.Xaml.Editors.TextBoxExt. The default value is null.

    CustomErrorIcon

    Gets or sets the custom Microsoft.UI.Xaml.Media.ImageSource used to display the error icon in the SfMaskedTextBox.

    Declaration
    public ImageSource CustomErrorIcon { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.Media.ImageSource

    A Microsoft.UI.Xaml.Media.ImageSource representing the source of the image to be displayed in theSyncfusion.UI.Xaml.Editors.TextBoxExt. The default value is null.

    Examples
      <syncfusion:SfMaskedTextBox CustomErrorIcon="Assets\error.png"
                                   ErrorType="Custom"
                                   MaskType="Simple"
                                   Mask="00/00/0000"/>  

    Description

    Gets or sets the content for control's description.

    Declaration
    public object Description { get; set; }
    Property Value
    Type Description
    System.Object

    It takes the object value. The default value is null.

    Examples
    <syncfusion:SfMaskedTextBox Description="SfMaskedTextBox"/>

    ErrorContent

    Gets or sets the error content for the SfMaskedTextBox control.

    Declaration
    public string ErrorContent { get; set; }
    Property Value
    Type Description
    System.String

    An System.String representing the error content. The default value is an empty string.

    Examples
    <syncfusion:SfMaskedTextBox ErrorContent="Invalid input"/>

    ErrorContentTemplate

    Gets or sets the content template for the error content.

    Declaration
    public DataTemplate ErrorContentTemplate { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.DataTemplate

    An Microsoft.UI.Xaml.DataTemplate Specifies the data template of the error content displayed in the Syncfusion.UI.Xaml.Editors.TextBoxExt. The default value is null.

    Examples
      <syncfusion:SfMaskedTextBox  ErrorType="Critical"
                                   MaskType="Simple"                
                                   Mask="00/00/0000">
          <Syncfusion:SfMaskedTextBox.ErrorContentTemplate>
               <DataTemplate>
                   <TextBlock Text = "Invalid Output" Foreground="BlueViolet" FontSize="22"/>
               </DataTemplate>
           </Syncfusion:SfMaskedTextBox.ErrorContentTemplate>
      </syncfusion:SfMaskedTextBox>

    ErrorType

    Gets or sets the error type for the SfMaskedTextBox control.

    Declaration
    public ErrorType ErrorType { get; set; }
    Property Value
    Type Description
    ErrorType

    It takes the object value. The default value is Default.

    Examples
    <syncfusion:SfMaskedTextBox ErrorType="Critical"/>

    Header

    Gets or sets the content for control's header.

    Declaration
    public object Header { get; set; }
    Property Value
    Type Description
    System.Object

    It takes the object value. The default value is null.

    Examples
    <syncfusion:SfMaskedTextBox Header="SfMaskedTextBox"/>

    HeaderTemplate

    Gets or sets the data template used to display the content of the control's header.

    Declaration
    public DataTemplate HeaderTemplate { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.DataTemplate

    It takes data template value. The default value is null.

    Examples
    <syncfusion:SfMaskedTextBox Header="SfMaskedTextBox">
       <syncfusion:SfMaskedTextBox.HeaderTemplate>
           <DataTemplate>
               <TextBlock Text = "{Binding}" FontWeight="Bold" />
           </DataTemplate>
     </syncfusion:SfMaskedTextBox.HeaderTemplate>
    </syncfusion:SfMaskedTextBox>

    Mask

    Gets or sets the mask value which restricts the inputs provided in the control.

    Declaration
    public string Mask { get; set; }
    Property Value
    Type Description
    System.String

    It takes the string value. The default value is null.

    MaskType

    Gets or sets the mask type for the SfMaskedTextBox control.

    Declaration
    public MaskedTextBoxMaskType MaskType { get; set; }
    Property Value
    Type Description
    MaskedTextBoxMaskType

    It takes the mask type value. The default value is Simple.

    Examples
    <syncfusion:SfMaskedTextBox MaskType="RegEx" Header="Email Input" Mask="[A-Za-z0-9-.%]+@[A-Za-z0-9]+.[A-Za-z]{3}"/>

    PromptChar

    Gets or sets a char which used as a prompt char of SfMaskedTextBox.

    Declaration
    public char PromptChar { get; set; }
    Property Value
    Type Description
    System.Char

    It takes the char value. The default value is "_".

    Text

    Gets or sets the displayed text of the SfMaskedTextBox control.

    Declaration
    public string Text { get; }
    Property Value
    Type Description
    System.String

    It takes the string value. The default value is empty.

    Value

    Gets or sets the input value for SfMaskedTextBox control.

    Declaration
    public object Value { get; set; }
    Property Value
    Type Description
    System.Object

    It takes the value of masked edit. The default value is null.

    Examples
    <syncfusion:SfMaskedTextBox MaskType="Simple" Mask="00/00/0000" Value="12"/>

    ValueMaskFormat

    Gets or sets the format for the value.

    Declaration
    public MaskedTextBoxMaskFormat ValueMaskFormat { get; set; }
    Property Value
    Type Description
    MaskedTextBoxMaskFormat

    It takes the mask format for the value. The default value is IncludePromptAndLiterals.

    Examples
    <syncfusion:SfMaskedTextBox Name="maskedTexBox" Mask="00/00/0000" Value="12" ValueMaskFormat="ExcludePromptAndLiterals"/>

    Methods

    OnApplyTemplate()

    Initializes the child elements.

    Declaration
    protected override void OnApplyTemplate()

    OnPointerEntered(PointerRoutedEventArgs)

    Handles the pointer entered event.

    Declaration
    protected override void OnPointerEntered(PointerRoutedEventArgs e)
    Parameters
    Type Name Description
    Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e

    OnPointerExited(PointerRoutedEventArgs)

    Handles the pointer exited event.

    Declaration
    protected override void OnPointerExited(PointerRoutedEventArgs e)
    Parameters
    Type Name Description
    Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e

    OnPreviewKeyDown(KeyRoutedEventArgs)

    Handles the preview key down event.

    Declaration
    protected override void OnPreviewKeyDown(KeyRoutedEventArgs e)
    Parameters
    Type Name Description
    Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e

    Events

    ValueChanged

    Invoke the event when the Value property is changed.

    Declaration
    public event EventHandler<MaskedTextBoxValueChangedEventArgs> ValueChanged
    Event Type
    Type
    System.EventHandler<MaskedTextBoxValueChangedEventArgs>

    ValueChanging

    Occurs when the value of the control is about to change.

    Declaration
    public event EventHandler<MaskedTextBoxValueChangingEventArgs> ValueChanging
    Event Type
    Type
    System.EventHandler<MaskedTextBoxValueChangingEventArgs>
    Remarks

    The ValueChanging event is raised when the value of the control is about to change. It provides an opportunity to perform additional actions or validation before the value is actually updated.

    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved