Articles → LIGHT SWITCH 2011 → Screen Lost Focus Event In Lightswitch 2011

Screen Lost Focus Event 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. Basics about lightswitch.
  2. How to create screens in lightswitch?
  3. How to create lightswitch project using visual studio?
  4. What are screens event?

Steps Of Execution




  1. Create a new project
  2. Add 2 screens
  3. Add code for screen’s lost focus



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