I wonder i some one have any good idea how to show the password in the PasswordBox. Have read that you can bind a textbox to a passwordbox but isnt it another way to do it.
-
1I always use TextBox for this purposes. Try it – Anton Semenov Jun 09 '13 at 08:10
-
I still want to hide the value in the textbox – codemoonger Jun 09 '13 at 08:12
-
1heh, as turned out its not trivial. look at http://stackoverflow.com/questions/10091466/showing-password-characters-on-some-event-for-passwordbox – Anton Semenov Jun 09 '13 at 08:23
-
**Related post** - [Where can I find a free masked TextBox in WPF?](https://stackoverflow.com/q/481059/465053) – RBT Apr 10 '18 at 07:04
3 Answers
If you want your password to be visible you should use a textbox. The only function of a password box is to mask input. It doesn't provide extra functionality. Its also possible to switch your textbox and password box at runtime

- 388
- 5
- 13
-
But if i have a textbox i want to be able to make it look like a passwordbox. So when i write in the textbox is dots instead of letters and then i have a button to show the actuall value – codemoonger Jun 09 '13 at 08:10
-
1In that case. Try this.myTextBox.PasswordChar = '*'. Let's see how this works – Remade Jun 09 '13 at 08:19
-
2"The only function of a password box is to mask input" - just wanted to point out that the WPF PasswordBox stores the value securely in memory in the SecurePassword property (which is a [SecureString](https://msdn.microsoft.com/en-us/library/system.security.securestring(v=vs.110).aspx)), which a TextBox doesn't do. – Richardissimo Jun 02 '18 at 06:40
There are no any inbuilt properties to show password character in PasswordBox control. But we could do this by TextBox control to display Password in PasswordBox. For PasswordBox with show/hide functionality in WPF. We will use Two TextBlock controls, TextBox control, PasswordBox control, Image control
XAML
<Grid>
<TextBlock Text="Welcome
To see the Password"
FontSize="28"
FontWeight="Bold"
HorizontalAlignment="Center"
VerticalAlignment="Top"
TextAlignment="Center"
Margin="0,30,0,0" />
<TextBlock Text="Enter your password"
FontSize="20"
HorizontalAlignment="Left"
Margin="112,160,0,0"
VerticalAlignment="Top" />
<TextBox Height="40"
FontSize="20"
Padding="5,2,47,0"
HorizontalAlignment="Left"
Margin="112,193,0,0"
Name="txtVisiblePasswordbox"
VerticalAlignment="Top"
Width="274" />
<PasswordBox Height="40"
FontSize="20"
Padding="5,2,47,0"
HorizontalAlignment="Left"
Margin="112,193,0,0"
Name="txtPasswordbox"
VerticalAlignment="Top"
Width="274"
PasswordChanged="txtPasswordbox_PasswordChanged" />
<Image Visibility="Hidden"
Height="30"
HorizontalAlignment="Left"
Name="ImgShowHide"
Stretch="Fill"
VerticalAlignment="Top"
Width="30"
Margin="351,198,0,0"
MouseLeave="ImgShowHide_MouseLeave"
PreviewMouseDown="ImgShowHide_PreviewMouseDown"
PreviewMouseUp="ImgShowHide_PreviewMouseUp" />
</Grid>
Code Behind
string AppPath = Directory.GetCurrentDirectory();
public MainWindow()
{
InitializeComponent();
ImgShowHide.Source = new BitmapImage(new Uri(AppPath + "\\img\\clip.jpg"));
}
private void ImgShowHide_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
HidePassword();
}
private void ImgShowHide_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
ShowPassword();
}
private void ImgShowHide_MouseLeave(object sender, MouseEventArgs e)
{
HidePassword();
}
private void txtPasswordbox_PasswordChanged(object sender, RoutedEventArgs e)
{
if(txtPasswordbox.Password.Length > 0)
ImgShowHide.Visibility = Visibility.Visible;
else
ImgShowHide.Visibility = Visibility.Hidden;
}
void ShowPassword()
{
ImgShowHide.Source = new BitmapImage(new Uri(AppPath + "\\img\\cus.jpg"));
txtVisiblePasswordbox.Visibility = Visibility.Visible;
txtPasswordbox.Visibility = Visibility.Hidden;
txtVisiblePasswordbox.Text = txtPasswordbox.Password;
}
void HidePassword()
{
ImgShowHide.Source = new BitmapImage(new Uri(AppPath + "\\img\\clip.jpg"));
txtVisiblePasswordbox.Visibility = Visibility.Hidden;
txtPasswordbox.Visibility = Visibility.Visible;
txtPasswordbox.Focus();
}

- 13,723
- 6
- 34
- 69
here's a good and easy way, u can just download the password font from Here and use it in the textbox as a font instead of passwordbox whenever you want to show a password all you have to do is just switch the fonts from "Password" to "Microsoft Sans Serif" or anything // For example when I click the CheckBox :
Private Sub ChkShowPass_Click(sender As Object, e As RoutedEventArgs)
If ChkShowPass.IsChecked = True Then
'show Password
TxtPassword.FontFamily = New FontFamily("Microsoft Sans Serif")
ElseIf ChkShowPass.IsChecked = False Then
'hide Password
TxtPassword.FontFamily = New FontFamily("Password")
End If
End Sub
hope this will help you and help many programmers.