In This Article

MaskedTextBox Class

Represents a TextBox that restricts input based on a specified mask.

public class MaskedTextBox : TextBox
Inheritance:
object Visual UIElement FrameworkElement Control TextBoxBase TextBox object

Constructors

MaskedTextBox()

Initializes an instance of the class.

public MaskedTextBox()

Properties

IsCaseAutoCorrected

Indicates whether characters entered will have their case auto-corrected to match the defined mask.

public bool IsCaseAutoCorrected { get; set; }

Property Value

bool:

true if characters entered will have their case auto-corrected to match the defined mask; otherwise, false. The default value is false.

Remarks

When this property is set to true, then the IsCaseSensitive property is ignored.

IsCaseSensitive

Indicates whether the mask is case sensitive.

public bool IsCaseSensitive { get; set; }

Property Value

bool:

true if the mask is case sensitive; otherwise, false. The default value is false.

Remarks

When the IsCaseAutoCorrected property is set to true, this property is ignored.

IsMatched

Indicates whether the input text successfully matches the pattern.

public bool IsMatched { get; }

Property Value

bool:

true if the input text successfully matches the pattern; otherwise, false.

Mask

The text that designates the input mask.

public string? Mask { get; set; }

Property Value

string:

The default value is null.

MaskKind

The kind of input mask.

public MaskKind MaskKind { get; set; }

Property Value

MaskKind:

The default value is Regex.

MatchedText

The matched text, which is generally the same as the Text property but without any prompt characters included.

public string MatchedText { get; set; }

Property Value

string

Remarks

Any bindings to MaskedTextBox should bind to this property instead of Text, so that prompt characters aren't included in the result.

PromptChar

The character used to indicate required input.

public char PromptChar { get; set; }

Property Value

char:

The default value is \u2022.

PromptVisibility

The visibility of mask prompts.

public MaskPromptVisibility PromptVisibility { get; set; }

Property Value

MaskPromptVisibility:

A MaskPromptVisibility that indicates the visibility of mask prompts. The default value is FocusedOnly.

Methods

OnGotFocus(RoutedEventArgs)

Invoked whenever an unhandled GotFocus event reaches this element in its route.

protected override void OnGotFocus(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

The RoutedEventArgs that contains the event data.

OnLostFocus(RoutedEventArgs)

Raises the LostFocus event (using the provided arguments).

protected override void OnLostFocus(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

Provides data about the event.

OnMouseDown(MouseButtonEventArgs)

Invoked whenever an unhandled System.Windows.Input.Mouse.MouseDown attached routed event reaches an element derived from this class in its route. Implement this method to add class handling for this event.

protected override void OnMouseDown(MouseButtonEventArgs e)
Parameter Type Description
e MouseButtonEventArgs

Provides data about the event.

Events

IsMatchedChanged

Occurs after the IsMatched property value changes.

public event EventHandler? IsMatchedChanged

Event Type

EventHandler

Fields

IsCaseAutoCorrectedProperty

Defines the IsCaseAutoCorrected property.

public static readonly DependencyProperty IsCaseAutoCorrectedProperty

IsCaseSensitiveProperty

Defines the IsCaseSensitive property.

public static readonly DependencyProperty IsCaseSensitiveProperty

IsMatchedProperty

Defines the IsMatched property.

public static readonly DependencyProperty IsMatchedProperty

MaskKindProperty

Defines the MaskKind property.

public static readonly DependencyProperty MaskKindProperty

MaskProperty

Defines the Mask property.

public static readonly DependencyProperty MaskProperty

MatchedTextProperty

Defines the MatchedText property.

public static readonly DependencyProperty MatchedTextProperty

PromptCharProperty

Defines the PromptChar property.

public static readonly DependencyProperty PromptCharProperty

PromptVisibilityProperty

Defines the PromptVisibility property.

public static readonly DependencyProperty PromptVisibilityProperty

Extension Methods