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.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<PasswordBox MaxLength="int"/>
Property Value
Type: System.Int32An 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).
| Exception | Condition |
|---|---|
| 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="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" />