locked
Close LightSwitch form on LostFocus RRS feed

  • Question

  • Is it possible to capture the LostFocus on a LightSwitch form to close the screen?
    Nigel Ainscoe
    Wednesday, November 9, 2011 3:51 PM

Answers

  • Are you meaning " the LostFocus on a LightSwitch form" = "screen's deactivation" ?

    Then may be so?

    using Microsoft.LightSwitch.Sdk.Proxy;
    using Microsoft.VisualStudio.ExtensibilityHosting;
    ...
            partial void <YourScreen>_Activated()
            {
                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.Close(true);
                });
            }
    
    

    (have to add reference Microsoft.LightSwitch.SDKProxy.dll in the Client proj)

    Thursday, November 10, 2011 10:38 AM

All replies

  • Does the lack of response mean that it is not possible to capture a screen's LostFocus event?
    Nigel Ainscoe
    Thursday, November 10, 2011 7:31 AM
  • Are you meaning " the LostFocus on a LightSwitch form" = "screen's deactivation" ?

    Then may be so?

    using Microsoft.LightSwitch.Sdk.Proxy;
    using Microsoft.VisualStudio.ExtensibilityHosting;
    ...
            partial void <YourScreen>_Activated()
            {
                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.Close(true);
                });
            }
    
    

    (have to add reference Microsoft.LightSwitch.SDKProxy.dll in the Client proj)

    Thursday, November 10, 2011 10:38 AM
  • That is what I mean. I will try this and see if it works for me and let you know.

    Thank you for your help.


    Nigel Ainscoe
    Thursday, November 10, 2011 11:16 AM
  • It would appear that this is a scenario that the LS team didn't anticipate, so no "LostFocus", or "Deactivated" event has been exposed for a "screen". I tried using the LayoutRoot to use a similar technique, but the ControlActivated method didn't fire for it (again something I guess wasn't thought necessary). Hopefully the next version will expose a fuller event model.

    The method explained above is using the navigation ViewModel to tell you when a screen has closed, and should work for you, but it's way more complicated than it really should be.


    Yann - LightSwitch Central

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    Thursday, November 10, 2011 11:18 AM
    Moderator
  • Works perfectly for me - thanks.
    Nigel Ainscoe
    Thursday, November 10, 2011 11:58 AM