Basic Features in .NET MAUI Masked Entry (SfMaskedEntry)

Setting ClearButtonVisibility

The ClearButtonVisibility of type ClearButtonVisibility controls whether a clear button is displayed, which enables the user to clear the text. The default value of this property is ClearButtonVisibility.Never.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          MaskType="Simple"
                          Mask="(000) 000-0000"
                          ClearButtonVisibility = "WhileEditing" />
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.MaskType = MaskedEntryMaskType.Simple;
maskedEntry.Mask = "(000) 000-0000";  
maskedEntry.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;

ClearButtonVisibility

Setting Clear Button Icon Color

The clear button icon color can be changed by using the ClearButtonColor.

<syncfusion:SfMaskedEntry x:Name="maskedEntry"
                          WidthRequest="200"
                          MaskType="Simple"
                          Mask="(000) 000-0000"
                          ClearButtonVisibility = "WhileEditing"
                          ClearButtonColor="Red" />
maskedEntry.ClearButtonColor = Colors.Red;

ClearButtonColor

Setting CursorPosition

The cursor position in the masked entry can either be obtained or updated using the CursorPosition property in SfMaskedEntry.

Setting FontSize

The Masked Entry control allows the user to customize the font size of the text inside the entry part using the FontSize property of type double.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          MaskType="Simple"
                          Mask="(000) 000-0000" Value="1234"
                          FontSize="18"/>
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.MaskType = MaskedEntryMaskType.Simple;
maskedEntry.Mask = "(000) 000-0000";  
maskedEntry.Value = 1234;
maskedEntry.FontSize = 18;

FontSize

Setting FontAttributes

The Masked Entry control allows the user to customize the font attribute of the text inside the entry part using the FontAttributes property of the type FontAttributes.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          MaskType="Simple"
                          Mask="(000) 000-0000" Value="1234"
                          FontAttributes="Bold"/>
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.MaskType = MaskedEntryMaskType.Simple;
maskedEntry.Mask = "(000) 000-0000";  
maskedEntry.Value = 1234;
maskedEntry.FontAttributes = FontAttributes.Bold;

FontAttributes

Setting FontFamily

The Masked Entry control allows the user to customize the text’s font family inside the entry part using the FontFamily property of the type string.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          MaskType="Simple"
                          Mask="(000) 000-0000" Value="1234"
                          FontFamily="Lobster-Regular"/>
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.MaskType = MaskedEntryMaskType.Simple;
maskedEntry.Mask = "(000) 000-0000";  
maskedEntry.Value = 1234;
maskedEntry.FontFamily = "Lobster-Regular";

FontFamily

Setting Keyboard

The Masked Entry control allows the user to specify the virtual keyboard displayed when entering text using the Keyboard property of type Keyboard.

Setting Placeholder

The Masked Entry control allows the user to define the text displayed when the Mask and Value are empty using the Placeholder property of type string. The default value of the Placeholder property is string.Empty.

<syncfusion:SfMaskedEntry WidthRequest="200"                         
                          Placeholder="Enter the value"/>
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.Placeholder = "Enter the value";

Placeholder

Setting PlaceholderColor

The SfMaskedEntry control allows the user to customize the color of the placeholder text using the PlaceholderColor property of type Color. The default value of the PlaceholderColor property is Colors.Gray.

<syncfusion:SfMaskedEntry WidthRequest="200"                         
                          Placeholder="Enter the value"
                          PlaceholderColor="Green"/>
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.Placeholder = "Enter the value"; 
maskedEntry.PlaceholderColor =  Colors.Green;

PlaceholderColor

Setting TextColor

The SfMaskedEntry control provides the user to customize the color of the entered text using the TextColor property of type Color. The default value of the TextColor property is Colors.Black.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          MaskType="Simple"
                          Mask="(000) 000-0000" Value="1234"
                          TextColor="Green"/>
maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.MaskType = MaskedEntryMaskType.Simple;
maskedEntry.Mask = "(000) 000-0000";  
maskedEntry.Value = 1234;
maskedEntry.TextColor =  Colors.Green;

TextColor

Stroke

The SfMaskedEntry border color can be changed by using the Stroke property.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          Mask="(000) 000-0000"
                          Stroke="Red"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = "200";
maskedEntry.Mask = "(000) 000-0000";
maskedEntry.Stroke = Colors.Red;

The following image illustrates the result of the above code:

ShowBorder

Border visibility

The ShowBorder property of SfMaskedEntry is used to modify the visibility of the border and its default value is true. The following code example demonstrates how to change the border visibility,

<syncfusion:SfMaskedEntry WidthRequest="200"
                          Mask="(000) 000-0000"
                          ShowBorder="False"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = 200;
maskedEntry.Mask = "(000) 000-0000";
maskedEntry.ShowBorder = false;

The following image illustrates the result of the above code:

ShowBorder

TextAlignment

The SfMaskedEntry provides support to customize the text alignment by using the HorizontalTextAlignment and VerticalTextAlignment properties.

<syncfusion:SfMaskedEntry WidthRequest="200"
                          HeightRequest="50"
                          HorizontalTextAlignment="Center" 
                          VerticalTextAlignment="Start"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry();
maskedEntry.WidthRequest = 200;
maskedEntry.HeightRequest = 50;
maskedEntry.HorizontalTextAlignment = TextAlignment.Center;
maskedEntry.VerticalTextAlignment = TextAlignment.Start;

The following image illustrates the result of the above code:

TextAlignment

ReturnType

The ReturnType property specifies the return button (e.g., Next, Done, Go) of the keyboard. It helps manage the flow between multiple input fields by defining what happens when the action button is pressed.

You can define the return key type of SfMaskedEntry by using the ReturnType property.

NOTE

Default value of ReturnType is Default.

<editors:SfMaskedEntry x:Name="maskedentry" 
                        WidthRequest="200"
                        ReturnType="Next"/>
SfMaskedEntry sfMaskedEntry = new SfMaskedEntry();
sfMaskedEntry.ReturnType = ReturnType.Next;

.NET MAUI MaskedEntry ReturnType

Clear button customization

The ClearButtonPath property allows users to set the path for customizing the appearance of the SfMaskedEntry clear button.

<editors:SfMaskedEntry x:Name="maskedEntry"
                       MaskType="Simple"
                       Mask="(000) 000-0000"
                       ClearButtonVisibility="WhileEditing">
            <editors:SfMaskedEntry.ClearButtonPath>
                <Path Data="M1.70711 0.292893C1.31658 -0.097631 0.683417 -0.097631 0.292893 0.292893C-0.097631 0.683417 -0.097631 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.097631 12.6834 -0.097631 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.097631 12.6834 -0.097631 12.2929 0.292893L7 5.58579L1.70711 0.292893Z" 
                Fill="Red" 
                Stroke="Red"/>
            </editors:SfMaskedEntry.ClearButtonPath>
</editors:SfMaskedEntry>
private string _customPath = "M1.70711 0.292893C1.31658 -0.097631 0.683417 -0.097631 0.292893 0.292893C-0.097631 0.683417 -0.097631 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.097631 12.6834 -0.097631 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.097631 12.6834 -0.097631 12.2929 0.292893L7 5.58579L1.70711 0.292893Z";

var converter = new PathGeometryConverter();
var path = new Path() 
{ 
    Data = (PathGeometry)converter.ConvertFromInvariantString(_customPath),
    Fill = Colors.Red,
    Stroke = Colors.Red
};

maskedEntry = new SfMaskedEntry();
maskedEntry.MaskType = MaskedEntryMaskType.Simple;
maskedEntry.Mask = "(000) 000-0000"; 
maskedEntry.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
maskedEntry.ClearButtonPath = path;

The following image illustrates the result of the above code:

.NET MAUI MaskedEntry ClearButtonPath

Return Command and Return Command Parameter

  • ReturnCommand, of type ICommand, defines the command to be executed when the return key is pressed.
  • ReturnCommandParameter, of type object, specifies the parameter for the ReturnCommand.
<ContentPage.BindingContext>
    <local:CommandDemoViewModel/>
</ContentPage.BindingContext>

<editors:SfMaskedEntry x:Name="maskedEntry"
            ReturnCommand="{Binding AlertCommand}"
            ReturnCommandParameter="Return key is pressed">
</editors:SfMaskedEntry>
var viewModel = new CommandDemoViewModel();

SfMaskedEntry maskedEntry = new SfMaskedEntry();
maskedEntry.ReturnCommand = viewModel.AlertCommand;
maskedEntry.ReturnCommandParameter = "Return key is pressed";
//ViewModel.cs

public class CommandDemoViewModel
{
    public ICommand AlertCommand => new Command<string>(OnAlertCommandExecuted);

    private async void OnAlertCommandExecuted(string parameter)
    {
        await Application.Current.MainPage.DisplayAlert("Alert", parameter, "OK");
    }
}