Top 10 Quick Tips for Building Great Mobile LightSwitch Apps

Top 10 Quick Tips for Building Great Mobile LightSwitch Apps

Rate This
  • Comments 18

I’ve been building a lot of HTML clients using LightSwitch lately so I thought I’d share some quick tips that you can use to build great mobile apps. (You’ll need Visual Studio 2012 Update 2 to get the LightSwitch HTML client.)

#1 – Prefer Tile Lists for Browse Screens and utilize Rows & Columns layouts

Because LightSwitch will automatically scale screens to fit different form factors, picking a Tile list instead of the default List control on your Browse Data screens can be a good idea, particularly if you have multiple fields you want to display on the tile. Utilize the Columns Layout control along with the Rows Layout to place data nicely on the tile. By default the tile width will adjust automatically to fill up the screen (but no smaller than the width you specify). If you always want a fixed with, select the Rows Layout and uncheck “Adjust Tile Width dynamically” in the properties window.

image

#2 – Show filters as Popups to conserve space

All screens have a Popups area at the bottom of the content tree that you can use to design “popup” dialogs specific to that screen. You can use them to display/collect additional or optional information on a screen. Prefer to utilize these popups on mobile devices when you’re designing your search screens. Your optional search fields won’t take up precious space which allows the important content to flow to the top.

To quickly add an optional filter, select “Edit Query” in your View Model in the Screen Designer…

image

Add a filter with optional parameters….

image

Select the Popup node in the tree and click “Add Popup”. Name the group “Filter”. Then drag the optional parameters into the popup group. This will automatically create local screen properties for you.

image

Finally add a button to the command bar and set the tap action to display the popup. Change the command bar icon to “Filter” in the properties window if you like.

image

When the user clicks the button, the popup filter is displayed:

image

Note that you may prefer to create a global query instead so you can reuse the filtered query across screens – see tip #6 below.

#3 – Consider your Master-detail options

A little while back I wrote about the different ways you can display master-detail data on screens. If you missed it: Master-Detail Screens with the LightSwitch HTML Client

Here are some tips from that article to keep in mind:

  • LightSwitch will automatically adjust the screen layout as necessary for different form factors. 
  • Using Tab controls for master-details screens is a good idea when you will potentially have a lot of child data to display or you are targeting smaller mobile devices like phones. This limits the amount of information that a user has to view/edit at once. This is the default layout you get on screens when you select multiple sets of data to display.
  • Showing all the data on a single tab works well for smaller sets of data where you’ll never have more than a handful of child data to view/edit at once (like in the following screenshot) or when your users are using larger devices like tablets.

image

#4 – Use Placeholder text to explain what the field is (like a short tool tip)

You don’t have tooltips on a mobile device (because you don’t have a mouse), so instead you can utilize the HTML5 placeholder text in input controls. Just set it in the property sheet and the text is displayed dimmed until the user enters some data.

image

#5 – Setting the fetch/page size

This tip applies to any client, not just mobile devices. LightSwitch automatically handles data loading asynchronously and in pages. For Browse Data screens the default page size is 45. On a mobile device, when users swipe to the end of a list the next page of 45 rows is dynamically loaded. You can set the page size in the screen designer. Select the Query in your view model and then set it via the properties window.

image 

#6 – Sort your data sets using screen or global queries

This tip applies to any type of screen on any device. By default the data in your data sources are retrieved in the order they were entered into the data source (oldest to newest) and that’s usually not the order we want data displayed. There’s a couple ways you can use queries to provide a base sort. If you’re using a set of data only on one screen, you can click the “Edit Query” link on your view model of the screen designer, just like in tip #2, and provide a sort there.

However, if you’re using a set of data across screens then it’s better to create a global query and use that on your screens. In fact, queries can be “built up” so you can use a query as the source of another query. That way you can have a base query that sorts the data and then you can use that as the source of subsequent queries. (For more info on queries see: Filtering Data with Queries on MSDN)

To create a global query, right-click on the Entity in the Solution Explorer and select “Add Query”, then define a sort using the query designer:

image

Now when you create additional queries you can use this sorted query as the source.

image

Once you have the global query set up the way you want, you can select the query as the screen data when creating screens. However if you already created a screen, you can change the source query by selecting the query in your view model in and setting the Query Source property.

image

 

#7 – Sort pickers using global queries

Similar to tip #6 above, you should also sort any data pickers on screens so that the list of choices are displayed sorted to the user. Create a global query that sorts the data like I showed above. Then to use the query as the source of the picker, first add the global query to your screen by clicking “Add Data Item…” button and selecting the sorted query you defined.

image

Then select the picker in the content tree and change the Choices property to the sorted query.

image

#8 – Use your own logo and splash screen images

If you want to specify a logo that appears on the Home screen (the first screen) of your mobile app, simply replace the default one. Flip to File View in the Solution Explorer…

image

Then expand the HTML client project’s content\images folder and replace the user-logo.png with your own image. If you want to also change the splash screen that is displayed when the app is loading, then replace the user-splash-screen.png.

image

#9 – Customize the login page

If you’re using Forms Authentication then you probably want to change the login page to also show your logo. Andy showed us how to do this in: Signed-In Part 4 – Authentication and Branding

While in File View, expand the Server project and you will see the LogIn.aspx and LogOut.aspx pages. Feel free to customize these pages exactly how you want.

image

For more information on LightSwitch authentication see: LightSwitch Authentication and Authorization on MSDN.

#10 – Make your apps pretty with ThemeRoller for jQuery Mobile

The easiest way to style a LightSwitch HTML client is to use ThemeRoller at http://jquerymobile.com/themeroller/. First decide on whether you want to go for a darker theme or a lighter theme because depending on that, you’ll want to first pick the corresponding LightSwitch theme which defines either black or white button images (for save, home, cancel, loading, etc.) as well as default text colors. LightSwitch comes with two built-in themes, the light theme (default) and the dark theme. To change to the dark theme, first flip to File View in the Solution Explorer and expand the HTML client project.

Open the default.htm and change the stylesheets to the dark theme:

<link rel="stylesheet" type="text/css" href="Content/dark-theme.css" />
<link rel="stylesheet" type="text/css" href="Content/msls-dark.css" />

Next open the dark-theme.css (or light-theme.css if you are using that) and copy the contents into your clipboard. Then click the “Import” button on ThemeRoller and paste the css into the window to import the theme. This will be your starting place for customizations.

image

Then simply drag colors from the palate to areas on the swatch, or modify the properties on the left to design your perfect theme.

image

When you’re done, click the Download button to name your theme and download your new CSS. Extract the zip, and then copy your theme to the content folder and update the default.htm to use it.

<link rel="stylesheet" type="text/css" href="Content/green-theme.css" />

image

#11 BONUS TIP! – Use Edit & Refresh when designing HTML screens

There’s one last bonus tip that I should mention that makes designing HTML client screens very quick. When you make any visual change in the screen designer, CSS or even change your JavaScript screen code, you don’t have to stop debugging to see the changes. Simply hit “Save all Files” in Visual Studio and then refresh your browser to see the changes applied.

I could go on with a lot more tips and tricks but these were the most important ones that came to mind when designing HTML client screens. You should be able to use them immediately to quickly make your mobile apps that much better. Got more tips? Add a comment below!

Enjoy!

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post
  • Thank you Beth, keep the articles coming!

  • These are great tips and info, Beth.

    Somehow I missed the introduction of the Data Picker into LS HTML.

    I'll have to study that one.

    Thanks for your continued articles.

  • Hi Beth,

    I can't see how to get the "picker in the content tree" referred to in  #7.

    Could this be a new screen entity hasn't been released yet ?

  • Hi Beth,

    thank you for your great articles about VS Lightswitch.

    I would be interested in Articles about typical JavaScript Screen code. Maybe you can provide us something

  • @John - Just create a relationship to a parent entity and LS will automatically create a picker for you. For instance a Customer entity has many Orders. Then when creating an Order Screen, LS will create a Customer picker for you.

    @Alex - We released a set of JavaScript code samples here: code.msdn.microsoft.com/.../JavaScript-for-LightSwitch-f1ec057c

    Community member Alessandro Del Sole then created an extension that adds them into your snippet library: visualstudiogallery.msdn.microsoft.com/442b5597-7489-4f31-b551-e45743fd64bd

    HTH,

    -Beth

  • Ah yes, Thanks Beth.

  • You have put renewed interested into considering LightSwitch for a future app design.

    Thank you.

  • Great article

  • Hi Beth,

    Just wonder is it possible for the HTML to capture photo using Phone 8 Camera instead of pick from storage. Looking forward to see you in SF Build 2013.  Thanks?

  • Is OK, I found the Answer in LightSwitch HTML Client Tutorial, Thanks

  • Thank you Beth for a great article! A question about tip #2: if you close the filter popup, the filter is still active. How can you reset the filter after closing the popup or with an additional button?

  • @Pieter-Jan - You can tap on the "X" on the search textbox to clear the search criteria in each field on the popup. Or you can easily add a button to the popup to clear all the fields. In the button execute you would write something like:

    myapp.BrowseCustomers.Clear_execute = function (screen) {

       // Write code here.

       screen.SearchField1  = "";

       screen.SearchField2  = "";

       screen.SearchField3 = "";

       ///etc...

       screen.closePopup();

    };

    Where SearchField1, 2, 3... are the screen query parameters that are added in the screen designer view model.

    Cheers,

    -Beth

  • Please Beth , how to use the logout.aspx page , I migrated from LS 2012 form authentication and all I need to make the user able to logout and redirect him again to the login page , I tried to call the logout.aspx by creating an empty screen and write this code on the run event :

    Dispatchers.Main.Invoke(Sub()

                                           HtmlPage.Window.Navigate(New Uri("LogOut.aspx", UriKind.Relative))

                                       End Sub)

    put it keep redirect me to "/Client/LogOut.aspx" , and when i tried to call the page directly it gives me error page  "Object reference not set to an instance of an object"

  • Amazing post. I am sure it will help us to create a superior <a href="http://www.mobilewebsite.com">Make a Mobile Website</a> for business if we can properly incorporate the tips you have shared with us. Thanks a lot.

  • Thank You Beth, for these tips, is there any example about the drag & drop for tiles on LS Html screens?

Page 1 of 2 (18 items) 12