Turn on to Microsoft’s LightSwitch

You won’t see the actual layout of the form until you run your application. Some will see this as a disadvantage, but you quickly become adept at reading the control tree and grasping what effect dragging controls around it will have.

Turn on to Microsoft's LightSwitch

Also, when you run the application you’ll see a button labelled Customize | Design Screen on the far right of the Ribbon, which lets you edit the screen layout and change the properties of the controls while the application is actually running. This is a reasonable compromise, although a preview of the screen at design time would be even better.

This way of laying out screens was first developed for the Work Items forms in Team Foundation Server, so anyone who has used TFS should be familiar with the square, boxy, regular layouts it encourages. This isn’t a criticism, far from it – whenever you produce a business application using Windows Forms or Windows Presentation Foundation, you can waste a great deal of time trying to get fields to line up and make grids fit just right.

Fields, grids, tabs and the rest automatically line up and fit into their containers, and if you don’t want them to, you have to say so

LightSwitch takes all that effort away. Fields, grids, tabs and the rest automatically line up and fit into their containers, and if you don’t want them to, you have to say so. All fields automatically receive labels calculated from their names – which you can override or hide if you want – and the fields and labels arrange themselves into neat columns, automatically based on the length of the longest in the group.

Missing features

There are some desirable layout options missing that may not be included by the final release date. There’s no box control for putting an outline and label around a set of other controls (an acceptable substitute can be a single tab).

It’s also difficult to put a label on its own onto the form, since you can only set the text it will show by writing code; placing a static image onto a form also involves writing a little code. Perversely, displaying images stored in the database on a form or grid is handled effortlessly straight out of the box, and such controls even sprout an upload button when you move the mouse over them at runtime.

Every grid knows how to export its contents to Excel, a feature you can turn off if it doesn’t make sense for a particular grid in your application.

There’s also a simple-to-implement extension which, by the addition of a button and one line of code, will import data from any Excel workbook or CSV file into any grid in your application: the import routine even takes care of all the field matching.

Columns in your workbook that have the same name as a field in your grid are automatically matched, and the user is given the opportunity to match the others – click the OK button and all the rows in the workbook are imported into the onscreen grid as new rows.

You can then edit the rows to fix any validation errors before clicking the Save button to commit the data to the database. This sort of capability usually involves hours and hours of programming and testing, but LightSwitch applications can have it for virtually no effort.

Stay secure

Security is another area in which most of the work has been done for you. You can set up security to allow all authenticated users or only named users to access the application, or else turn off security altogether.

You get the ability to set permissions, roles and users tables, plus all the screens necessary to assign roles to users and permissions to roles. All you need to do is define the permissions and check them at the appropriate point in the application. Say you wanted to secure a button called Approve, then you’d write one line of code in the appropriate event handler:

Private Sub Approve_CanExecute(ByRef
result as Boolean)
result = Application.User.
HasPermission(“CanApprove”)
End Sub

If any one of the user’s roles has the “CanApprove” permission then the Approve button will be available to them: if none of their roles has that permission, the button will be greyed out. This is the right way to do security, and LightSwitch applications get it all with only one click of the mouse.

LightSwitch can be extended using custom controls, and extensions are already available to integrate with Bing Maps and SQL Server Reporting Services. Virtually any Silverlight control can be wrapped in some fairly simple code to turn it into a LightSwitch extension.

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.

Todays Highlights
How to See Google Search History
how to download photos from google photos