Here, we will see how to write code for a specific screen in a LightSwitch Application using Visual Studio 2012.
The following is the procedure for writing code for a specific screen.
Step 1
Go to the Solution Explorer as shown below.
Step 2
Right-click on "Data sources" and choose "Add Table".
Step 3
The table opens in the Data Designer.
In this way we can add as many tables as we want to our application. Here I am adding only one table.
Step 4
Now once again go to the Solution Explorer and right-click on Screen and choose "Add Screen".
The Add New Screen dialog box appear on the screen. Select the "New Data Screen" from the Screen Template, under screen information, choose "Employee" under screen data and provide some name to the Screen and click the "OK" button.
The Screen Designer appears as shown below.
From the command bar in the Screen Designer choose "Write code".
Step 5
A drop down list will appear. From the drop down list choose a method for that specific screen.
Suppose I have chosen the CreateNewEmployee_Created method from the write code.
A ".cs" file will open that consists of the following code. You can provide further code for that screen.
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;
namespace LightSwitchApplication
{
public partial class CreateNewEmployee
{
partial void CreateNewEmployee_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)
{
// Write your code here.
this.EmployeeProperty = new Employee();
}
partial void CreateNewEmployee_Saved()
{
// Write your code here.
this.Close(false);
Application.Current.ShowDefaultScreen(this.EmployeeProperty);
}
partial void CreateNewEmployee_Created()
{
// Write your code here.
}
}
}