Silverlight has a special control for Password fields. It's called PasswordBox.
Here is the sample of XAML with PasswordBox:
<PasswordBox Password="HelloWorld" x:Name="pbPassword">
Another surprise from Silverlight development team is that PasswordBox control doesn't have Text property. In order to retrieve the value of the Password field use the Password property instead:
string sPassword = tbPassword.Password;
Recently I had to work on a prototype where TextBox control was originally used for collecting password information. So, I went and replaced TextBox control with Password control and then changing Text property to Password. Guess what, my code compiled fine but when I tried to run it, it crashed. The reason was in Style property.
<PasswordBox Password="HelloWorld" x:Name="pbPassword"
Style="{StaticResource myTextBoxStyle}" >
This style was defined for the TextBox. This style is not compatible with PasswordBox control. I didn't have a chance to look at what exactly in myTextBoxStyle style is causing problems. I will find it out and update this post.
One more note about PasswordBox is that it has PasswordChar property which can be used to specify the masking character. It's a nice useless feature with no real value. It would be much nicer if PasswordBox was inherited from TextBox so developers won't spend their valuable time building special cases around this control.
Oleg.
No comments:
Post a Comment