Articles → LIGHT SWITCH 2011 → Refresh Other Screen Data In Lightswitch 2011
Refresh Other Screen Data In Lightswitch 2011
Software Requirement
- Visual studio 2010 is installed on your machine.
- Visual Studio 2010 service pack 1 is installed on your machine.
- Microsoft Visual Studio Light switch 2011 is installed on your machine.
Prerequisite Knowledge
- How to create a lightswitch project?
- How to create screen in lightswitch?
- How to add button in lightswitch application?
- What is button’s execute method?
- How to create a lightswitch project?
Create A New Project
Click to Enlarge
Add Screens In The Project
Click to Enlarge
Iscreenobject And Application.Activescreens
Click to Enlarge
Add Refresh Button
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);
- As I am going to refresh the EditableGrid screen that is why I am passing EditableGrid in the angled bracket.
- 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();
});
}