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.
Step 2
In the Solution Explorer, right-click on the Data Source and choose "Add Table".
Step 3
The table appears.
Step 4
In the Solution Explorer, right-click on the Screens and choose "Add Screen".
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".
Step 6
The Screen Designer appears.
Step 7
In the Screen Designer by default for the word field a TextBox is available.
Step 8
From the drop down list choose the custom control option.
Step 9
Go to the property window for the word control and click on the "Change" hyperlink.
Step 10
The Add Custom Control dialog box appears on the window screen.
Step 11
In the Add Custom Control select the System.Windows.Controls node and choose the wordBox option and click "OK".
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.