How to create a PasswordBox in WPF

The PasswordBox element in XAML represents a WPF PasswordBox. A PasswordBox is used to handle passwords in WPF.

The MaxLength property is used to set maximum length of a password. PasswordChar property represents the character used to hide the password and PasswordChanged event is fired when a password is changed.

The following code snippet creates a PasswordBox in WPF using C#.

<PasswordBox Width="250" Height="30"

                  Background="LightSalmon"

                  Name="pwdBox"

                  MaxLength="64"

                  PasswordChar="#"

                  PasswordChanged="pwdBox_PasswordChanged" 

        />

Here is the PasswordChanged event handler.

private void pwdBox_PasswordChanged(object sender, RoutedEventArgs e)

{

 

}