How to quit the entire Microsoft Lightswitch application?

In this example I will demonstrate how to quit the entire Microsoft Lightswitch application and at the same time provide you an example on how to use the built-in MessageBox class.  The two activities are crucial to my application life cycle.  So here is it:

Put the code below to a method, for example, a Quit method:

            If Me.ShowMessageBox(“Are you sure you want to quit?”, “Quit”, MessageBoxOption.YesNo) = System.Windows.MessageBoxResult.Yes Then
                Dispatchers.Main.Invoke(Sub()
                                            If System.Windows.Application.Current.IsRunningOutOfBrowser Then
                                                System.Windows.Application.Current.MainWindow.Close()
                                            Else
                                                System.Windows.Browser.HtmlPage.Window.Invoke(“close”)
                                            End If
                                        End Sub)
            End If

Thats it. If you find an error upon pasting the code above just include the reference.

Advertisements

3 thoughts on “How to quit the entire Microsoft Lightswitch application?

  1. Hi, thank you for sharing this.. I’m new to LS and this post helped me with my concern. although, I have another concern and I hope you could help me too. In the attached screenshot, you have a modified login screen. I’m particularly interested on how you incorporated the “Branch” field with a dropdown list. Can you show me how you were able to accomplish this.. Thanks in advance.

    1. I did not use the built-in security of lightswitch, you can only customize it through the shell, instead I use a simple home screen with a user and password field. Then record the current user in the application class that will be consumed by all screen on created event.

  2. C# Code:

    partial void _Closing(ref bool cancel)
    {
    if (this.ShowMessageBox(“Are you sure you want to quit?”, “Quit”, MessageBoxOption.YesNo) == System.Windows.MessageBoxResult.Yes)
    {
    Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() => {
    if (System.Windows.Application.Current.IsRunningOutOfBrowser) {
    System.Windows.Application.Current.MainWindow.Close();
    } else {
    System.Windows.Browser.HtmlPage.Window.Invoke(“close”);
    }
    });
    }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s