articles

PasswordBox Control in WPF

Anonymous User20352 01-Apr-2011

XAML <PasswordBox /> elements represent password control in WPF. When we make any login form then we want user can enter their password in such a manner that other user cannot see what he enter. To implement this type of functionality we use PasswordBox control in WPF. Textbox control does not provide any functionality to use it as a password control. If you want that user can enter information in secure manner then we have to use PasswordBox control to implement this type of functionality. In this demonstration I will show you that how to use PasswordBox control in WPF.

Code snippet for creating a simple PasswordBox control

<PasswordBox Width="200" Height="30"/>

This code snippet represents a simple PasswordBox control in which we can enter secure information.

Output of this code snippet

PasswordBox Control in WPF

Setting PasswordChar property to PasswordBox control

We can use PasswordChar to change the password character of the PasswordBox control. The following code snippet represents PasswordBox control with PasswordChar property.

<PasswordBox Width="200" Height="30" PasswordChar="*" />

 The output of the following code snippet is as follows

PasswordBox Control in WPF

Retrieving values from PasswordBox control

We can use PasswordBox property to retrieve values from PasswordBox control. The following code snippet represents use of Password property.

<PasswordBox x:Name="userPassword" Width="200" Height="30" PasswordChar="*" />
        <TextBlock x:Name="txtOutput" Width="200" Height="30" Text="Output" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,80,0,0" />
        <Button x:Name="btngetPassword" Width="200" Height="30" Content="Get Password" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,130,0,0" Click="btngetPassword_Click" />
Output of the following code snippet

PasswordBox Control in WPF

 

Business Login To Retrive Values From Password Control
private void btngetPassword_Click(object sender, RoutedEventArgs e)
{
            txtOutput.Text = "Password You Entered  :  " + userPassword.Password;
}

 

Output of the following code snippet is as follows 

PasswordBox Control in WPF

In this code snippet after entering password when user click on Get Password button the password that user had entered is displayed if text block control.

 

 


Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By