Implementing a Home Screen
Out of the box, LightSwitch doesn't offer a screen template to create a home screen, which would be useful to introduce users to the application and to provide shortcuts to screens or additional resources. If you have experience with Microsoft Access, you might recall the command panel forms where you could add buttons and launch tasks; in LightSwitch, something similar would certainly be interesting.
But it's quite easy to make a home screen of your own. Continuing the previous discussion of how to add static images to an empty screen, we can extend the screen with some text and commands. Figure 8 shows the result that you'll reach moments from now.
Basically you'll need to do the following:
- Add a new group of type Rows Layout under the logo.
- Add a Local Property of type String called WelcomeMessage and place it inside the previous group. This property will contain an informational message. Change the Font Style property to Heading 1.
- Add a new group of type Tabs Layout under the Rows Layout created earlier (but don't make it nested).
- Add a new group called Columns Layout inside the Tabs Layout. Change the value of the Display Name property to Tasks.
- Add two buttons inside the Command Bar of the Columns Layout. Change their appearance to Hyperlink.
- Update the InitializeDataWorkspace method hook to assign the WelcomeMessage property:
- The next step is handling the Execute method hook of each button. Depending on the name you've given to the buttons' methods, write code similar to the following:
- Run the application. You'll get a result similar to what you see in Figure 9.
Private Sub Home_InitializeDataWorkspace(saveChangesTo As System.Collections. Generic.List(Of Microsoft.LightSwitch.IDataService)) Me.CustomLogo = GetImageByName("CompanyLogo.png") Me.WelcomeMessage = "Welcome to the Fantastic Company's application" End Sub
Private Sub OpenScreenOne_Execute() Application.ShowScreenOne() End Sub
Replace OpenScreenOne with the name of your button and ShowScreenOne with the method that will open the appropriate screen.
This is just an example of how you can create and customize a home screen for your applications.