I want to make a TextBox's Text display like a PasswordBox's Text. Is there any way by which I can do it? I think styling the TextBox may work. I tried to style it using PasswordBox's default style (http://msdn.microsoft.com/en-us/library/dd334412.aspx) but it didn't work.
Asked
Active
Viewed 2,849 times
3 Answers
1
Use an IValueConverter
in wich you replace each character in the Text
variable of your TextBox with a *
, then put the resulting string of stars in the tag property of your TextBox.
This way, your textbox is not showing the actual string edited (which is a password here if i understood you right).
In your binding, put UpdateSourceTrigger="PropertyChanged"
to get it updated on every key instead of on LostFocus. Then bind the text displayed to the TextBox.Tag
property.

Louis Kottmann
- 16,268
- 4
- 64
- 88
-
I can't spare the time right now anymore, but to point you in the right direction i updated my post. – Louis Kottmann Jul 31 '11 at 18:47
0
You can try this by adding FontFamily
of the TextBox
as following:
<TextBox Text="{Binding YOUR_PROPERTY}"
FontFamily="ms-appx:///Assets/PassDot.ttf#PassDot"
FontSize="35"/>
In my case this worked just fine.

Tasnim Fabiha
- 1,148
- 1
- 17
- 31
-
-
@Hacki https://github.com/davidagraf/passwd/blob/master/public/ttf/password.ttf you can download this from here. Back then I downloaded it from some git link like this, and that worked. I'm sure this will also work. – Tasnim Fabiha Jun 03 '21 at 12:30
-
-
Hi @Hacki , if the downloaded font is not working for you, can you check this answer here? https://stackoverflow.com/a/54677658/3939811 – Tasnim Fabiha Jun 08 '21 at 12:31
0
There is a PasswordBox in WPF since .Net 3.0 onwards.
http://www.wpftutorial.net/PasswordBox.html
Is this what you are looking for?

WPF-it
- 19,625
- 8
- 55
- 71
-
Is there any reasons why you dont want to use the PasswordBox? Is there something it is not allowing you to do? – WPF-it Jul 31 '11 at 17:33
-
6