Clever Humans


Clever Humans do the darnedest things!


11 November 2007

Simple WPF PasswordBox Answer

by Patrick

If you use a PasswordBox in WPF, the property you need to use to read the password typed in by the user is called “Password.”

Obviously the developer(s) of this control thought this was a perfectly cromulent and obvious name for the value that contains the password. Maybe it’s just me, but it wasn’t obvious at all. This is mostly because every single other control uses either .Text or .Content to hold their content. You would naturally expect the password control to follow a similar convention (there are two, pick one). Unfortunately, instead it uses a property unique to this control to handle this data in a manner that no other password control does.

Maybe I am the only person who has had a problem figuring out how to get the value from this contorl. In googling for the answer I didn’t find it. I downloaded the sample from MSDN and, believe it or not, in the entire sample they demonstrate many ways to use the control except, well, reading a value from it.

The only way I found the answer is that I have the book Windows Presentation Foundation Unleashed by Adam Nathan.

tags: programming