How to make a Password using Textbox in Microsoft Lightswitch?

A password-masked text box is normally not a problem but when I tried to used it in Microsoft Ligthswitch it was a horrific experience.  Anyways I got it figured out and here are the steps:

1. Add a Data Item in the Screen and name it Password

2. Drag it to the screen, see the sample screen below:

3. The default control of the Password data type is a Textbox you must change it to a Custom Control -> PasswordBox (Windows Control)

4. Now that the Password control has been painted into your screen, its time to make it functioning by using the following code below:

Private Sub pwdAvailable(sender As Object, e As ControlAvailableEventArgs)
AddHandler CType(e.Control, System.Windows.Controls.Control).LostFocus, AddressOf PasswordLostFocus
End Sub

Private Sub PasswordLostFocus(sender As Object, e As System.Windows.RoutedEventArgs)
Me.Password = CType(sender, System.Windows.Controls.PasswordBox).Password
End Sub

5.  Then add code below in your screen initialize data workspace.

AddHandler Me.FindControl("Password").ControlAvailable, AddressOf pwdAvailable

That’s it, below is the sample screen where I use the password-masked textbox.  This is the login screen on my application.

Advertisements

One thought on “How to make a Password using Textbox in Microsoft Lightswitch?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s