Refresh Another Screen in LightSwitch 2012

This article shows how to refresh another screen in a LightSwitch Application (Visual C#) in Visual Studio 2012.

The following is the procedure for refreshing another screen in LightSwitch 2012.

Step 1

Open the Solution Explorer.

solEx.jpg

Step 2


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

Add Screen.jpg

Step 3

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

New.jpg

The Screen Designer appears.

src desi1.jpg

Step 4

In the same manner we are going to add another screen. But this time we will add an "Editable Grid Screen".

editable.jpg

The Screen Designer appears.

sec desi2.jpg

Step 5

Open the Screen Designer for Create New Screen and add a button.

Add button.jpg

The Add Button dialog box appears on the screen.

dialog box.jpg

Now the screen designer contains a button.

Step 6

Right-click on that button and and select the "_Execute" method.

execute method.jpg

The code designer appears.

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 Microsoft.LightSwitch.Client;

namespace LightSwitchApplication

{

    public partial class CreateNew

    {

        partial void RefreshScreen_Execute()

        {

            // Write your code here.

            RefreshScreenClass.RefreshSrc<EditableGrid>(Application.ActiveScreens);

        }

    }

    public static class RefreshScreenClass

    {

        public static void RefreshSrc<R>(this IList<IActiveScreen> screenList) where R : IScreenObject

        {

            var src = screenList.Where((x) => x.Screen is R); // Here screenList contain the list of Active Screen

 

            foreach (var s in src)

            {

                var screen = (R)s.Screen;

 

                screen.Details.Dispatcher.BeginInvoke(() =>

                {

                    screen.Refresh(); //It refreshes the Screen

                });

            }

        }

    }

}

In the "execute()" Method, a static method called RefreshSrc is called, that is defined in the RefreshScreen class.

In order

Step 7

Press F5 to run the application.

out1.jpg

Click on the refresh button. This will refresh the Editable Grid Screen.

out2.jpg


Similar Articles