0

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.

Elmo
  • 6,409
  • 16
  • 72
  • 140

3 Answers3

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
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
  • link on where to download the PassDot.ttf @Tasnim Fabiha – paraJdox1 May 29 '21 at 11:22
  • @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
  • the "space" is not turned into a password character - • though ;( – paraJdox1 Jun 04 '21 at 05:32
  • 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