Articles → LIGHT SWITCH 2011 → Refresh Other Screen Data In Lightswitch 2011

Refresh Other Screen Data In Lightswitch 2011






Software Requirement




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.

Prerequisite Knowledge




  1. How to create a lightswitch project?
  2. How to create screen in lightswitch?
  3. How to add button in lightswitch application?
  4. What is button’s execute method?
  5. How to create a lightswitch project?

Create A New Project




Picture showing the lightswitch project structure in solution explorer
Click to Enlarge


Add Screens In The Project




Picture showing the screens added in the lightswitch project
Click to Enlarge


Iscreenobject And Application.Activescreens




Picture showing the screen that specifies the difference between IScreenObject and Application.ActiveScreens
Click to Enlarge




Add Refresh Button




Picture showing a button to refresh another screen in lightswitch
Click to Enlarge


Adding Code In Refresh’S Execute Event




public partial class CreateNew {
  partial void RefreshOtherScreen_Execute() {
    ScreenRefreshClass.RefreshScreen < EditableGrid > (Application.ActiveScreens);
  }
}

public static class ScreenRefreshClass {
  public static void RefreshScreen < T > (this IList < IActiveScreen > screenList) where T: IScreenObject {
    var screens = screenList.Where((x) => x.Screen is T);

    foreach(var s in screens) {
      var screen = (T) s.Screen;

      screen.Details.Dispatcher.BeginInvoke(() => {
        screen.Refresh();
      });
    }
  }
}



Code Explanation






ScreenRefreshClass.RefreshScreen<EditableGrid>(Application.ActiveScreens);


  1. As I am going to refresh the EditableGrid screen that is why I am passing EditableGrid in the angled bracket.
  2. The parameter Application.ActiveScreens contains an IEnumerable of IActiveScreens (i.e. CreateNew and EditableGrid screen in this case).


var screens = screenList.Where((x) => x.Screen is T);






foreach(var s in screens) {
  var screen = (T) s.Screen;

  screen.Details.Dispatcher.BeginInvoke(() => {
    screen.Refresh();
  });
}





Posted By  -  Karan Gupta
 
Posted On  -  Monday, August 27, 2012

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250