Click here to Skip to main content
6,629,377 members and growing! (24,298 online)
Email Password   helpLost your password?
Web Development » Silverlight » Controls     Beginner License: The Code Project Open License (CPOL)

Silverlight Password Box

By Maciej Gren

An small article about how to create simple password text box in Silverlight 2 Beta 2
C# (C# 1.0, C# 2.0, C# 3.0), Windows, Visual Studio (VS2008), Dev, Design
Posted:30 Jun 2008
Views:17,839
Bookmarked:24 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
7 votes for this article.
Popularity: 3.10 Rating: 3.67 out of 5
1 vote, 14.3%
1

2
2 votes, 28.6%
3
1 vote, 14.3%
4
3 votes, 42.9%
5
PasswordBox

Introduction

While digging into Silverlight 2 Beta 2 I have noticed that there is no Password Box available. It will be in a finall version but till then we have to figure out some other way to do it. This solution is quick and maybe even a little bit dirty but it works what makes it valuable enough to be posted :)

Using the code

Just attach the tbPassword_TextChanged method (from the attached example) to your password text box (simple Silverlight Text Box).

          
string _currentText = "";

void tbPassword_TextChanged(object sender, TextChangedEventArgs e)

{

    TextBox __textBox = sender as TextBox;

    if (__textBox != null)

    {

        string __currentText = __textBox.Text;

        if (__currentText.Length < _currentText.Length)

            _currentText = _currentText.Substring(0, __currentText.Length);

        if (__currentText != "")

        {

            for (int i = 0; i < __currentText.Length; i++)

            {

                if (__currentText[i] != '\u25CF')

                {
            
                    string __temp = __currentText.Remove(i, 1);

                    __textBox.Text = __temp.Insert(i, "\u25CF");

                    _currentText = _currentText.Insert(_currentText.Length, __currentText[i].ToString());

 

                }

            }

        }

    }

}
        

In the _currentText you will find text from the password box.

Points of Interest

I am working on quite big RIA Silverlight application. Lacking this basic password box made my stomach aches. Hopefully in final release of Silverlight we wont have such issues anymore.

History

While creating this small sample I was inspired by Michael Sync post. Unfortunatly, Silverlight 2 beta 2 sample source code did not work properly that is why I decided to write simplier solution (IMHO).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Maciej Gren


Member
I started work with .Net in year 2005. During my studies I was a team leader of project which scored 4th place on Polish Imagine Cup Finals where we delivered WPF application with https WCF services. Meanwhile I have worked on Windows Mobile Applications with Windows CE 5.0. I have learned how to create Windows CE Images using Platform Builder and I gained high skills in Compact Framework 2.0. After one year of developing using this framework I have switched to ASP.Net. Currently I am using Monorail Framework together with Active Record and Extjs library (for presentation layer). I am a Team Leader in GOYELLO where we delivered quite successful projects. My aim is to develop good quality applications but not forgetting about reality. Always there are some drawbacks on each solution. The case is to find the proper balance Smile
Occupation: Team Leader
Company: GOYELLO
Location: Poland Poland

Other popular Silverlight articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
GeneralSome changes for given code [modified] Pinmemberintrosas8:24 19 Sep '08  
QuestionConnection with the server? Pinmembersydaze4:23 10 Sep '08  
GeneralWorks just fine, just add "__textBox.Select(__textBox.Text.Length, 1);" to the end ... Pinmemberericsson00715:16 22 Aug '08  
GeneralIl y a beaucoup plus simple Pinmembermandark.dev11:04 14 Aug '08  
GeneralSilverlight can use build-in html control? PinmemberJcmorin4:55 1 Jul '08  
GeneralRe: Silverlight can use build-in html control? PinmemberMaciej Gren11:35 1 Jul '08  
Generalvalidating User Name & Password Pinmember248912821:03 30 Jun '08  
GeneralRe: validating User Name & Password PinmemberMaciej Gren8:34 1 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 30 Jun 2008
Editor:
Copyright 2008 by Maciej Gren
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project