Developing a Password TextBox Control in LightSwitch Using Visual Studio 2012

Developing a word TextBox Control in LightSwitch using Visual Studio 2012

This article describes how to develop a word 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 word field a TextBox is available.

drop down text box.jpg

Step 8

From the drop down list choose the custom control option.

custom field word.jpg

Step 9

Go to the property window for the word 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 wordBox option and click "OK".

word box select.jpg

Step 12

To save the content of the wordbox 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("word").ControlAvailable += wordavailable;

        }

 

        private void wordavailable(object sender, ControlAvailableEventArgs e)

        {

            //throw new NotImplementedException();

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

        }

 

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

        {

            //throw new NotImplementedException();

            this.UserProperty.word = ((System.Windows.Controls.wordBox)sender).word;

        }

 

        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

Up Next
    Ebook Download
    View all
    Learn
    View all