Articles → LIGHT SWITCH 2011 → Screen lost focus event in lightswitch 2011

Screen lost focus event in lightswitch 2011




















Software requirement











Prerequisite knowledge













Steps of execution













Create a new project




Picture showing the project structure of the lightswitch application in the solution explorer

Click to Enlarge


Add 2 screens




Picture showing the 2 screens added in the lightswitch application

Click to Enlarge


Add code for screen’s lost focus




using Microsoft.VisualStudio.ExtensibilityHosting;
using Microsoft.LightSwitch.Presentation.Extensions;
using Microsoft.LightSwitch.Sdk.Proxy;

namespace LightSwitchApplication {
  public partial class Screen_one {
    partial void Screen_one_Activated() {
      IServiceProxy proxy = VsExportProviderService.GetExportedValue < IServiceProxy > ();
      VsExportProviderService.GetExportedValue < IServiceProxy > ().ActiveScreensViewModel.PropertyChanged += ActiveScreensViewModel_PropertyChanged;
    }

    void ActiveScreensViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
      this.Details.Dispatcher.BeginInvoke(() => {
        VsExportProviderService.GetExportedValue < IServiceProxy > ().ActiveScreensViewModel.PropertyChanged -= ActiveScreensViewModel_PropertyChanged;
        this.ShowMessageBox("Screen deactivated event fired");
      });
    }
  }
}



Output




Picture showing the screen one loaded when the application runs for the first time

Click to Enlarge



Picture showing the message box appeared when focus on lost from screen 1 to screen 2

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, June 1, 2013

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250