Reader Level:
ARTICLE

Developing a Password TextBox Control in LightSwitch Using Visual Studio 2012

Posted by Ashwani Tyagi Articles | LightSwitch 2012 June 14, 2013
This article describes how to develop a Password TextBox Control in LightSwitch using Visual Studio 2012.
  • 0
  • 0
  • 4400

Developing a Password TextBox Control in LightSwitch using Visual Studio 2012

This article describes how to develop a Password TextBox Control in LightSwitch using Visual Studio 2012.

Procedure for displaying data on a blank screen in LightSwitch using Visual Studio 2012

Step 1

Open the Solution Explorer.

sol exp.jpg

Step 2

In the Solution Explorer, right-click on the Data Source and choose "Add Table".

add table.jpg

Step 3

The table appears.

user.jpg

Step 4

In the Solution Explorer, right-click on the Screens and choose "Add Screen".

add src.jpg

Step 5

Select "Add New Screen" from the Screen Templates. Under Screen Information we provide the Screen Name and Screen Data and then click "OK".

add new screen.jpg

Step 6

The Screen Designer appears.

app designer.jpg

Step 7

In the Screen Designer by default for the password field a TextBox is available.

drop down text box.jpg

Step 8

From the drop down list choose the custom control option.

custom field password.jpg

Step 9

Go to the property window for the password control and click on the "Change" hyperlink.

prop change.jpg

Step 10

The Add Custom Control dialog box appears on the window screen.

add custom control.jpg

Step 11

In the Add Custom Control select the System.Windows.Controls node and choose the PasswordBox option and click "OK".

password box select.jpg

Step 12

To save the content of the passwordbox we will do some coding.

using System;

using System.Linq;

using System.IO;

using System.IO.IsolatedStorage;

using System.Collections.Generic;

using Microsoft.LightSwitch;

using Microsoft.LightSwitch.Framework.Client;

using Microsoft.LightSwitch.Presentation;

using Microsoft.LightSwitch.Presentation.Extensions;

using System.Windows.Controls;

 

namespace LightSwitchApplication

{

    public partial class CreateNewUser

    {

        partial void CreateNewUser_InitializeDataWorkspace(List<IDataService> saveChangesTo)

        {

            // Write your code here.

            this.UserProperty = new User();

            this.FindControl("Password").ControlAvailable += passwordavailable;

        }

 

        private void passwordavailable(object sender, ControlAvailableEventArgs e)

        {

            //throw new NotImplementedException();

            ((Control)e.Control).LostFocus += PasswordLostFocus;

        }

 

        private void PasswordLostFocus(object sender, System.Windows.RoutedEventArgs e)

        {

            //throw new NotImplementedException();

            this.UserProperty.Password = ((System.Windows.Controls.PasswordBox)sender).Password;

        }

 

        partial void CreateNewUser_Saved()

        {

            // Write your code here.

            this.Close(false);

            Application.Current.ShowDefaultScreen(this.UserProperty);

        }

    }

}

Step 13

Now press F5 to run the application.

output.jpg

COMMENT USING

Trending up