![]() |
Web Development »
Silverlight »
Controls
Beginner
License: The Code Project Open License (CPOL)
Silverlight Password BoxBy Maciej GrenAn 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
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 :)
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.
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.
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).
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
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 |