Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #47 – How to Implement a Password Box

With the release of Silverlight 2 RC0 there are three new controls we will be discussing that were not available for beta 2. The three new controls with a Tip of the Day for each include:

For this tip we will be exploring the PasswordBox control. Password boxes are great in that they hide the characters a user is typing for privacy and security reasons. It is essential to use this control whenever you are receiving a password from a user.

The following code below shows how to declare, size and position a password box in your XAML:

<PasswordBox Canvas.Top="20" x:Name="UserPassword"  Width="200"></PasswordBox>

By default Silverlight uses a “dot” as the character to hide the characters the user typed.

image

You can override this character using the PasswordChar property:

<PasswordBox PasswordChar="*" Canvas.Top="20" x:Name="UserPassword"  Width="200"></PasswordBox>

image

You can also do all this programmatically in your code behind:

PasswordBox passBox = new PasswordBox();
passBox.Width = 200;
passBox.SetValue(Canvas.TopProperty, (double)300);
passBox.PasswordChar = '*';
MyCanvas.Children.Add(passBox);

Note that we have to take the extra step to add it to our Canvas control so that it appears in the element tree.

Thank you,
--Mike Snow

 Subscribe in a reader

Comments

Microsoft Weblogs said:

With the release of Silverlight 2 RC0 there is are a number of new controls that were not available in

# September 29, 2008 2:30 PM

Silverlight Tips of the Day - Blog by Mike Snow said:

With the release of Silverlight 2 RC0 there are three new controls we will be discussing that were not

# September 29, 2008 3:16 PM

Silverlight Tips of the Day - Blog by Mike Snow said:

With the release of Silverlight 2 RC0 there are three new controls we will be discussing that were not

# September 29, 2008 5:41 PM

Silverlight Tip of the Day #47 ??? How to Implement a Password Box - Silverlight Tips of the Day - Blog by Mike Snow said:

Pingback from  Silverlight Tip of the Day #47 ??? How to Implement a Password Box - Silverlight Tips of the Day - Blog by Mike Snow

# September 29, 2008 5:44 PM

2008 September 30 - Links for today « My (almost) Daily Links said:

Pingback from  2008 September 30 - Links for today &laquo; My (almost) Daily Links

# September 30, 2008 3:52 AM

Silverlight news for September 30, 2008 said:

Pingback from  Silverlight news for September 30, 2008

# September 30, 2008 9:45 AM

Dew Drop – September 30, 2008 (Evening Edition) | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop &ndash; September 30, 2008 (Evening Edition) | Alvin Ashcraft's Morning Dew

# September 30, 2008 10:28 PM

Community Blogs said:

In this post: Mike Snow, Bill Reiss, Jesse Liberty, Harsh Bardhan, Tim Heuer, Matthias Shapiro, and Jeff

# October 1, 2008 9:53 AM

Visual Web Developer Team Blog said:

Silverlight Tip of the Day #57 Title: How to Dynamically Load a Silverlight Control within another Silverlight

# October 8, 2008 11:06 PM

{Dev Tricks} » Blog Archive » Silverlight - Password field no longer missing said:

Pingback from  {Dev Tricks}  &raquo; Blog Archive   &raquo; Silverlight - Password field no longer missing

# October 9, 2008 9:35 AM

MS Tech News » Silverlight Tips of the Day ??? Week 8 said:

Pingback from  MS Tech News &raquo; Silverlight Tips of the Day ??? Week 8

# October 27, 2008 3:27 PM

MS Tech News » Silverlight Tips of the Day ??? Week 8 said:

Pingback from  MS Tech News &raquo; Silverlight Tips of the Day ??? Week 8

# October 27, 2008 3:33 PM