Xceed DataGrid for WPF v7.2 Documentation
MaskedTextBox Class
Members  Example 


Xceed.Wpf.Controls Assembly > Xceed.Wpf.Controls Namespace : MaskedTextBox Class
Represents a control that limits the inputted text to be of the format determined by the specified mask.
Syntax
'Declaration
 
<LocalizabilityAttribute(LocalizationCategory.Text)>

<ContentPropertyAttribute("Text")>

<TemplatePartAttribute(Name="PART_ContentHost", Type=System.Windows.FrameworkElement)>

<StyleTypedPropertyAttribute(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)>

<XmlLangPropertyAttribute("Language")>

<UsableDuringInitializationAttribute(True)>

<RuntimeNamePropertyAttribute("Name")>

<UidPropertyAttribute("Uid")>

<TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>

<NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>

Public Class MaskedTextBox 

   Inherits ValueRangeTextBox
'Usage
 
Dim instance As MaskedTextBox
[Localizability(LocalizationCategory.Text)]

[ContentProperty("Text")]

[TemplatePart(Name="PART_ContentHost", Type=System.Windows.FrameworkElement)]

[StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]

[XmlLangProperty("Language")]

[UsableDuringInitialization(true)]

[RuntimeNameProperty("Name")]

[UidProperty("Uid")]

[TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]

[NameScopeProperty("NameScope", System.Windows.NameScope)]

public class MaskedTextBox : ValueRangeTextBox 
Example
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
The following example demonstrates how to use the MaskedTextBox control outside a grid to allow a user to input a fictitious identity number. The foreground color of the masked text box will change from red when it contains invalid text (HasParsingError), to blue when all required characters have been inputted (IsMaskCompleted), to green when all characters, required and optional, have been inputted (IsMaskFull).
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"

      xmlns:s="clr-namespace:System;assembly=mscorlib">

  <Grid.Resources>  

<Style TargetType="{x:Type xcdg:MaskedTextBox}">

      <Style.Triggers>

         <Trigger Property="HasParsingError" Value="True">

            <Setter Property="Foreground" Value="Red" />

         </Trigger>



         <Trigger Property="IsMaskCompleted" Value="True">

           <Setter Property="Foreground" Value="Blue" />

        </Trigger>

       

        <Trigger Property="IsMaskFull" Value="True">

           <Setter Property="Foreground" Value="Green" />

        </Trigger>

     </Style.Triggers>

  </Style>

  </Grid.Resources>

    <xcdg:MaskedTextBox Mask=">LLLL 000000 ??"

                        PromptChar="-"

                        AllowPromptAsInput="True"

                        ResetOnPrompt="True"

                        ResetOnSpace="True"

                        Height="Auto"/>

  </Grid>
Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     System.Windows.Controls.Primitives.TextBoxBase
                        System.Windows.Controls.TextBox
                           Xceed.Wpf.Controls.AutoSelectTextBox
                              Xceed.Wpf.Controls.ValueRangeTextBox
                                 Xceed.Wpf.Controls.MaskedTextBox
                                    Xceed.Wpf.Controls.DateTimeTextBox

Requirements

Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

MaskedTextBox Members
Xceed.Wpf.Controls Namespace