Getting Started with .NET MAUI Masked Entry

This section guides you through setting up and configuring a Masked Entry in your .NET MAUI application. Follow the steps below to add a basic Masked Entry to your project.

To quickly get started with the .NET MAUI Masked Entry, watch this video.

Prerequisites

Before proceeding, ensure the following are in place:

  1. Install .NET 8 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio 2022 (v17.8 or later).

Step 1: Create a New MAUI Project

  1. Go to File > New > Project and choose the .NET MAUI App template.
  2. Name the project and choose a location. Then, click Next.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI Inputs NuGet Package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.Inputs and install the latest version.
  3. Ensure the necessary dependencies are installed correctly, and the project is restored.

Step 3: Register the handler

Syncfusion.Maui.Core nuget is a dependent package for all Syncfusion® controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion® core.

  • C#
  • using Microsoft.Maui;
    using Microsoft.Maui.Hosting;
    using Microsoft.Maui.Controls.Compatibility;
    using Microsoft.Maui.Controls.Hosting;
    using Microsoft.Maui.Controls.Xaml;
    using Syncfusion.Maui.Core.Hosting;
    
    namespace MaskedEntrySample
    {
        public static class MauiProgram
        {
            public static MauiApp CreateMauiApp()
            {
                var builder = MauiApp.CreateBuilder();
                builder
                .UseMauiApp<App>()
                .ConfigureSyncfusionCore()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });
    
                return builder.Build();
            }      
        }
    }

    Step 4: Add a Basic Masked Entry

    Step 1: Add the namespace as shown in the following code sample.

    <xmlns:editors="clr-namespace:Syncfusion.Maui.Inputs;assembly=Syncfusion.Maui.Inputs"/>
    using Syncfusion.Maui.Inputs;

    Step 2: Add the SfMaskedEntry control with a required optimal name using the included namespace.

    <editors:SfMaskedEntry x:Name="maskedentry" />
    SfMaskedEntry maskedEntry = new SfMaskedEntry();

    Prerequisites

    Before proceeding, ensure the following are set up:

    1. Install .NET 8 SDK or later is installed.
    2. Set up a .NET MAUI environment with Visual Studio Code.
    3. Ensure that the .NET MAUI extension is installed and configured as described here.

    Step 1: Create a New MAUI Project

    1. Open the Command Palette by pressing Ctrl+Shift+P and type .NET:New Project and press Enter.
    2. Choose the .NET MAUI App template.
    3. Select the project location, type the project name and press Enter.
    4. Then choose Create project

    Step 2: Install the Syncfusion® MAUI Inputs NuGet Package

    1. Press Ctrl + ` (backtick) to open the integrated terminal in Visual Studio Code.
    2. Ensure you’re in the project root directory where your .csproj file is located.
    3. Run the command dotnet add package Syncfusion.Maui.Inputs to install the Syncfusion® .NET MAUI Inputs package.
    4. To ensure all dependencies are installed, run dotnet restore.

    Step 3: Register the handler

    Syncfusion.Maui.Core nuget is a dependent package for all Syncfusion® controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion® core.

  • C#
  • using Microsoft.Maui;
    using Microsoft.Maui.Hosting;
    using Microsoft.Maui.Controls.Compatibility;
    using Microsoft.Maui.Controls.Hosting;
    using Microsoft.Maui.Controls.Xaml;
    using Syncfusion.Maui.Core.Hosting;
    
    namespace MaskedEntrySample
    {
        public static class MauiProgram
        {
            public static MauiApp CreateMauiApp()
            {
                var builder = MauiApp.CreateBuilder();
                builder
                .UseMauiApp<App>()
                .ConfigureSyncfusionCore()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });
    
                return builder.Build();
            }      
        }
    }

    Step 4: Add a Basic Masked Entry

    Step 1: Add the NuGet to the project as discussed in the above reference section.

    Step 2: Add the namespace as shown in the following code sample.

    <xmlns:editors="clr-namespace:Syncfusion.Maui.Inputs;assembly=Syncfusion.Maui.Inputs"/>
    using Syncfusion.Maui.Inputs;

    Step 3: Add the SfMaskedEntry control with a required optimal name using the included namespace.

    <editors:SfMaskedEntry x:Name="maskedentry" />
    maskedEntry = new SfMaskedEntry();

    Step 5: Adding Mask to the Masked Entry

    Initialize MaskedEntry control using simple mask

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

    Simple mask in .NET MAUI Masked Entry.

    Initialize MaskedEntry control using RegEx mask

    <editors:SfMaskedEntry WidthRequest="200"
                              ClearButtonVisibility="WhileEditing"
                              MaskType="RegEx"
                              Mask="[A-Za-z0-9._%-]+@[A-Za-z0-9]+.[A-Za-z]{2,3}" />
    SfMaskedEntry maskedEntry = new SfMaskedEntry();
    maskedEntry.WidthRequest = 200;
    maskedEntry.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
    maskedEntry.MaskType = MaskedEntryMaskType.RegEx;
    maskedEntry.Mask = "[A-Za-z0-9._%-]+@[A-Za-z0-9]+.[A-Za-z]{2,3}";

    RegEx mask in .NET MAUI Masked Entry.

    Setting the prompt character

    Every single mask displays a prompt character (‘_’) in the absence of your input. Customize this prompt character by using the PromptChar property.

    <editors:SfMaskedEntry WidthRequest="200"
                              ClearButtonVisibility="WhileEditing"
                              MaskType="Simple"
                              Mask="00/00/0000"
                              PromptChar="#" />
    SfMaskedEntry maskedEntry = new SfMaskedEntry();
    maskedEntry.WidthRequest = 200;
    maskedEntry.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
    maskedEntry.MaskType = MaskedEntryMaskType.Simple;
    maskedEntry.Mask = "00/00/0000";
    maskedEntry.PromptChar = '#';

    .NET MAUI Masked Entry prompt character.

    Setting the value

    The Value property sets the input value for the MaskedEntry control.

    <editors:SfMaskedEntry WidthRequest="200"
                              ClearButtonVisibility="WhileEditing"
                              MaskType="Simple"
                              Mask="00/00/0000"
                              Value="12/02/2022" />
    SfMaskedEntry maskedEntry = new SfMaskedEntry();
    maskedEntry.WidthRequest = 200;
    maskedEntry.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
    maskedEntry.MaskType = MaskedEntryMaskType.Simple;
    maskedEntry.Mask = "00/00/0000";
    maskedEntry.Value = "12/02/2022";

    .NET MAUI Masked Entry value.

    NOTE

    Get the complete getting started sample from the GitHub link.

    NOTE

    You can refer to our .NET MAUI Masked Entry feature tour page for its groundbreaking feature representations. You can also explore our .NET MAUI Masked Entry Example that shows you how to render the Masked Entry in .NET MAUI.