Articles → LIGHT SWITCH 2011 → Refresh other screen data in lightswitch 2011

Refresh other screen data in lightswitch 2011






















Software requirement











Prerequisite knowledge















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);








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