MaxLength Property
Collapse the table of content
Expand the table of content

PasswordBox.MaxLength Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the maximum length for passwords to be handled by this PasswordBox.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public int MaxLength { get; set; }
<PasswordBox MaxLength="int"/>

Property Value

Type: System.Int32
An integer specifying the maximum length, in character, for passwords to be handled by this PasswordBox.
A value of zero (0) means no limit.
The default value is 0 (no length limit).


The property is set to a negative value.

Dependency property identifier field: MaxLengthProperty

This property only restricts password entered manually by the user; it has no effect on programmatic manipulation of the Password property.

The following snippet sets the MaxLength property to 8. This example is part of a larger example available in the PasswordBox class overview.

<TextBlock Text="Type password here" Margin="20,10,0,0"/>
<PasswordBox x:Name="MyPWBox1" Margin="20,10,0,0" PasswordChanged="MyPWBox1_PasswordChanged" 
             MaxLength="8" Height="70" Width="200" HorizontalAlignment="Left" />
<TextBlock Text="Password" Margin="20,10,0,0"/>
<TextBox x:Name="ReadOnlyTB" Margin="20,10,0,0" HorizontalAlignment="Left" 
         IsReadOnly="True" Height="70" Width="200" />

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2018 Microsoft