PasswordBox.MaxLength Property

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)

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).

ExceptionCondition
ArgumentOutOfRangeException

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="35" 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="35" Width="200" />


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: