WPF PasswordBox Control:
The PasswordBox control is used to take sensitive or private information input from the user. It has been designed to keep in mind to handle the password.
<PasswordBox /> create the passwordBox control in XAML.
Properties:
Password property contains the password in the passwordbox and PasswordChar is the masking character for the password.
Following tag create the Password Box control with the masking character as * and maximum password length of 50 characters.
<PasswordBox Height="23" Margin="40,74,118,0" Name="PasswordBox1" VerticalAlignment="Top" PasswordChar="*" MaxLength="50" />
Events:
PasswordChanged event is main event of the control and is raised when password property has been changed.
To handle the event add the PasswordChanged="Password1_OnPasswordChanged" in the xaml and write the handler as
protected void Password1_OnPasswordChanged(object sender, RoutedEventArgs e)
{
Console.WriteLine(PasswordBox1.Password);
}
Download the attached code to run and see how PasswordBox Control works.
Summary:
PasswordBox control is specially designed for the password in the WPF. Its similar to TextBox Control except the masking the text and TextBox has Text Property to get and set the text, where as PasswordBox contains the Password property to get and set the password text.