Difference Between Programmer Created Detail Screen and LightSwitch Generated Detail Screen

This article explains how a Detail Screen is created by a programmer as well as how a Detail Screen is generated in a LightSwitch Application (Visual C#) in Visual Studio 2012.

The following is the procedure for a programmer to create a LightSwitch Detail Screen.

Step 1

Open the Solution Explorer.

solEx.jpg

Step 2

In the Solution Explorer, right-click on the Server and choose "Add Table" option.

Add Table.jpg

Step 3

The Person Table appears.

table.jpg

Step 4

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

Add src.jpg

Step 5

The Add New Screen dialog box appears. Select the "New Data Screen" from the Screen Template, under screen information, choose "Person" under screen data and provide a name to the Screen, and click the "OK" button.

new src.jpg

The Screen Designer appears for the New Data Screen.

src desi.jpg

Step 6

Add another screen. This time we will add a Detail Screen for the Person Table. Remember to uncheck the checkbox "Use as Default Detail Screen" when we add a Detail Screen.

detail src.jpg

The Screen Designer appears for the Details Screen.

Src designer.jpg

Step 7

Open the Screen Designer for the New Data Screen and go to the menu bar and choose the "Write Code" drop down list item and then choose the "_Saved()" method.

Writecode.jpg

The code designer appears. In this we need not change anything, the code will be added automatically.

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 CreateNewPerson

    {

        partial void CreateNewPerson_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)

        {

            // Write your code here.

            this.PersonProperty = new Person();

        }

 

        partial void CreateNewPerson_Saved()

        {

            // Write your code here.

            this.Close(false);

            Application.Current.ShowDefaultScreen(this.PersonProperty);

        }

    }

}

Step 8

Press F5 to run the application.

output1.jpg

Step 9

Now make some changes in the code
as in the following:

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 CreateNewPerson

    {

        partial void CreateNewPerson_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)

        {

            // Write your code here.

            this.PersonProperty = new Person();

        }

 

        partial void CreateNewPerson_Saved()

        {

            // Write your code here.

            this.Close(false);

            Application.Current.ShowPersonDetail(this.PersonProperty.Id);

        }

    }

}

 

Step 10

Now once again, press F5 to run the application.

output2.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all