syncfusion/wpf-ui-components-skills / skills/syncfusion-wpf-maskedtextbox
syncfusion-wpf-maskedtextbox
VerifiedComprehensive guide for implementing Syncfusion WPF MaskedTextBox (SfMaskedEdit) control for restricted input with mask patterns. Use this skill when implementing masked input, input masks, or input restrictions with predefined patterns in WPF. Covers phone number input, email validation, credit card input, formatted input with prompt characters, RegEx masks, and custom patterns for dates, currency, product keys, and zip codes.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.0 KB |
| references/appearance-customization-themes.md | markdown | 6.5 KB |
| references/appearance-customization.md | markdown | 9.4 KB |
| references/getting-started.md | markdown | 9.6 KB |
| references/mask-patterns-advanced.md | markdown | 2.1 KB |
| references/mask-patterns-input-restriction.md | markdown | 14.2 KB |
| references/value-management-advanced.md | markdown | 5.4 KB |
| references/value-management.md | markdown | 11.2 KB |
references/getting-started.md
View on GitHub# Getting Started with SfMaskedEdit
This guide covers installation, setup, and basic configuration of the Syncfusion WPF MaskedTextBox (SfMaskedEdit) control.
## Assembly Deployment
### Required Assemblies
To use SfMaskedEdit, you need the following assemblies:
- **Syncfusion.SfInput.WPF** - Contains SfMaskedEdit control
- **Syncfusion.SfShared.WPF** - Shared utilities and dependencies
### Installation Methods
#### Method 1: NuGet Package Manager (Recommended)
```powershell
Install-Package Syncfusion.SfInput.WPF
```
The NuGet package automatically includes all required dependencies.
#### Method 2: Package Manager UI
1. Right-click your project in Solution Explorer
2. Select "Manage NuGet Packages"
3. Search for "Syncfusion.SfInput.WPF"
4. Click "Install"
#### Method 3: Syncfusion Control Panel
Install the complete Syncfusion WPF suite via the Control Panel installer, then add assembly references manually.
**Assembly Location:**
`C:\Program Files (x86)\Syncfusion\Essential Studio\<version>\precompiledassemblies\<.NET version>\`
### Verify Installation
After installation, verify the assemblies are referenced:
- Open Solution Explorer
- Expand "References" or "Dependencies"
- Confirm `Syncfusion.SfInput.WPF` and `Syncfusion.SfShared.WPF` are listed
## Adding SfMaskedEdit via Designer
If you have Syncfusion installed, you can drag SfMaskedEdit from the toolbox:
1. Open your XAML file in the designer
2. Open the Toolbox (View → Toolbox)
3. Locate "Syncfusion Controls for WPF"
4. Find "SfMaskedEdit" and drag it to your window/page
5. The required assemblies are automatically added
The designer adds the namespace and control:
```xml
<syncfusion:SfMaskedEdit x:Name="sfMaskedEdit"
Width="200"
Height="30"/>
```
## Adding SfMaskedEdit via XAML
### Step 1: Create a WPF Project
1. Open Visual Studio
2. Create a new WPF Application project
3. Target .NET Framework 4.6.2 or higher (or .NET 5/6/7/8)
### Step 2: Add Assembly References
Add the required NuGet package or assembly references as described above.
### Step 3: Import the Namespace
Add the Syncfusion namespace to your XAML window/page:
```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
x:Class="YourNamespace.MainWindow"
Title="MaskedEdit Sample" Height="450" Width="800">
```
**Namespace breakdown:**
- `xmlns:syncfusion` - Prefix for Syncfusion controls
- `http://schemas.syncfusion.com/wpf` - Syncfusion WPF schema URI
### Step 4: Declare the Control
Add SfMaskedEdit to your layout:
```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
x:Class="SfMaskedEditSample.MainWindow"
Title="SfMaskedEdit Sample" Height="350" Width="525">
<Grid>
<syncfusion:SfMaskedEdit x:Name="sfMaskedEdit"
Width="200"
Height="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</Window>
```
## Adding SfMaskedEdit via C#
### Step 1: Create WPF Project and Add References
Follow the same project creation and reference steps as above.
### Step 2: Import the Namespace in Code
Add the using directive in your code-behind or view model:
```csharp
using Syncfusion.Windows.Controls.Input;
```
### Step 3: Create and Configure the Control
```csharp
using System.Windows;
using Syncfusion.Windows.Controls.Input;
namespace SfMaskedEditSample
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// Create an instance of SfMaskedEdit
SfMaskedEdit sfMaskedEdit = new SfMaskedEdit();
sfMaskedEdit.Width = 200;
sfMaskedEdit.Height = 30;
sfMaskedEdit.HorizontalAlignment = HorizontalAlignment.Center;
sfMaskedEdit.VerticalAlignment = VerticalAlignment.Center;
// Add to the window
this.Content = sfMaskedEdit;
}
}
}
```
### Adding to Existing Layout
If you have an existing Grid or other layout:
```csharp
public MainWindow()
{
InitializeComponent();
// Create the control
SfMaskedEdit sfMaskedEdit = new SfMaskedEdit
{
Name = "phoneInput",
Width = 200,
Height = 30,
Margin = new Thickness(10)
};
// Add to existing Grid (assuming Grid is named "MainGrid")
MainGrid.Children.Add(sfMaskedEdit);
}
```
## Basic Mask Configuration
### Setting a Simple Mask
```xml
<syncfusion:SfMaskedEdit Mask="-?\d+\.?\d*"
MaskType="RegEx"
PromptChar="_"
x:Name="numericInput"/>
```
```csharp
SfMaskedEdit numericInput = new SfMaskedEdit();
numericInput.MaskType = MaskType.RegEx;
numericInput.Mask = @"-?\d+\.?\d*";
numericInput.PromptChar = '_';
```
**This mask accepts:**
- Positive and negative numbers
- Whole numbers and decimals
- Example inputs: `123`, `-45`, `12.34`, `-98.76`
### Common Initial Configurations
#### Phone Number
```xml
<syncfusion:SfMaskedEdit
Mask="\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}"
MaskType="RegEx"
PromptChar="_"/>
```
#### Email Address
```xml
<syncfusion:SfMaskedEdit
Mask="[A-Za-z0-9._%-]+@[A-Za-z0-9]+\.[A-Za-z]{2,3}"
MaskType="RegEx"/>
```
#### Currency
```xml
<syncfusion:SfMaskedEdit
Mask="$ \d+\.\d{2}"
MaskType="RegEx"
Value="100.00"/>
```
## Setting Initial Values
You can set an initial value using the `Value` property:
```xml
<syncfusion:SfMaskedEdit
Value="4553456789"
Mask="\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}"
MaskType="RegEx"
x:Name="phoneNumber"/>
```
```csharp
SfMaskedEdit phoneNumber = new SfMaskedEdit();
phoneNumber.Value = "4553456789";
phoneNumber.MaskType = MaskType.RegEx;
phoneNumber.Mask = @"\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}";
```
The value is automatically formatted according to the mask:
- **Input:** `"4553456789"`
- **Displayed:** `(455) 345-6789`
## Handling ValueChanged Events
Subscribe to the `ValueChanged` event to respond when the user modifies the value:
### In XAML
```xml
<syncfusion:SfMaskedEdit ValueChanged="SfMaskedEdit_ValueChanged"
Mask="\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}"
MaskType="RegEx"
x:Name="phoneInput"/>
```
### In Code-Behind
```csharp
public MainWindow()
{
InitializeComponent();
phoneInput.ValueChanged += PhoneInput_ValueChanged;
}
private void PhoneInput_ValueChanged(object sender, EventArgs e)
{
var maskedEdit = sender as SfMaskedEdit;
string currentValue = maskedEdit.Value;
// Check if input is valid
if (!maskedEdit.HasError)
{
MessageBox.Show($"Valid phone number: {currentValue}");
}
else
{
MessageBox.Show("Please enter a valid phone number");
}
}
```
### When Does ValueChanged Fire?
The event fires based on the `ValidationMode` property:
- **KeyPress** (default): Fires on each valid keystroke
- **LostFocus**: Fires only when the control loses focus
```xml
<syncfusion:SfMaskedEdit
ValidationMode="LostFocus"
ValueChanged="SfMaskedEdit_ValueChanged"/>
```
## Complete Getting Started Example
A compact example demonstrating a minimal setup with phone and email fields.
### XAML
```xml
<Window x:Class="MaskedEditDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
Title="MaskedEdit Demo" Height="300" Width="400">
<StackPanel Margin="20">
<syncfusion:SfMaskedEdit x:Name="phoneInput"
Mask="\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}"
MaskType="RegEx"
PromptChar="_"
Watermark="(___) ___-____"
Width="200"/>
<syncfusion:SfMaskedEdit x:Name="emailInput"
Mask="[A-Za-z0-9._%-]+@[A-Za-z0-9]+\.[A-Za-z]{2,3}"
MaskType="RegEx"
Watermark="example@domain.com"
Width="250"/>
</StackPanel>
</Window>
```
### Code-Behind (minimal)
```csharp
using System.Windows;
namespace MaskedEditDemo
{
public partial class MainWindow : Window
{
public MainWindow() => InitializeComponent();
}
}
```
See `references/mask-patterns-input-restriction.md` for a comprehensive list of masks and examples.
## License Configuration
Syncfusion controls require a license key. Register it in your App.xaml.cs:
```csharp
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// Register Syncfusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR_LICENSE_KEY");
base.OnStartup(e);
}
}
```
**Get your license key:** Obtain a license key from the Syncfusion licensing portal or your Syncfusion account dashboard.
## Next Steps
Now that you have SfMaskedEdit set up, explore:
- **Mask Patterns:** Learn to create custom masks for any format
- **Value Management:** Control how values are formatted
- **Appearance:** Customize colors, borders, and themes
- **Validation:** Implement KeyPress or LostFocus validation
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 470k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |