MaskedTextInput

RadMaskedTextInput represents a control that can be used to restrict the input of text values.

In order to use the RadMaskedCurrencyInput control in your projects you have to add references to the following assemblies:

  • Telerik.Windows.Controls
  • Telerik.Windows.Controls.Input
  • Telerik.Windows.Data

You can find more info here.

Declaratively defined MaskedTextInput

The following example shows how to define the control and set few of its properties.

Example 1: Define RadMaskedTextInput in XAML

<telerik:RadMaskedTextInput EmptyContent="Enter digits" 
                            InputBehavior="Replace" 
                            Mask="a20" 
                            SelectionOnFocus="SelectAll" 
                            TextMode="PlainText" 
                            UpdateValueEvent="LostFocus" 
                            Value="Sample Text" /> 

Figure 2: RadMaskedTextInput example

Data Binding

RadMaskedTextInput's Value property is of type string and you have to bind it to ViewModel's property of type string.

Binding to object is not support and may result in unpredictable behavior.

Example 2: Define the view model

public class ViewModel : ViewModelBase 
{ 
    private string text; 
 
    public ViewModel() 
    { 
        this.Text = "Sample Text"; 
    } 
 
    public string Text 
    { 
        get { return this.text; } 
        set 
        { 
            if (this.text != value) 
            { 
                this.text = value; 
                this.OnPropertyChanged("Text"); 
            } 
        } 
    } 
} 

Example 3: Binding the Value property

<telerik:RadMaskedTextInput EmptyContent="Enter digits" 
                            InputBehavior="Replace" 
                            Mask="a20" 
                            SelectionOnFocus="SelectAll" 
                            TextMode="PlainText" 
                            UpdateValueEvent="LostFocus" 
                            Value="{Binding Text}" /> 

Setting the Value Mode

The value mode allows you to set the behavior of the Value property in a mask scenario (when the Mask property is set). By default the Value property holds the characters without including the placeholders and the literals defined in the mask. You can alter this and allow the value to hold also literal and placeholders by setting the ValueMode property of the control.

Read more about this in the Value Mode article.

FormatString

You can format the entered value using the FormatString property of the RadMaskedTextInput control. The property works with the standard .NET string formats. The format will be applied only when the control is unfocused.

Example 4: Setting the FormatString property

<telerik:RadMaskedTextInput Value="Adam" 
                            Mask="a4"  
                            FormatString="{}UserName: {0} NickName: {0}"/> 

Figure 2: Showing the text value when the control is focused

Figure 3: Showing the text value when the control is unfocused

See Also

In this article
Not finding the help you need? Improve this article