Add Buttons and Commands in LightSwitch 2012

In this article you will learn how to use commands as buttons and links in LightSwitch 2012.

Getting Started

  1. Open Visual Studio 2012.
  2. Go to "File" => "New" => "Project..."
  3. Select "LightSwitch" in installed templates.
  4. Select "LightSwitch Application (Visual C#)".
  5. Enter the Name and choose the location.
  6. Click "OK".

First of all add a data source and add a search screen and add a button to the screen command bar.


Image 1.

Select the "New Method" radio button and provide a method name and click the "OK" button.


Image 2.

You will see that a new method has been added.


Image 3.

If you want to add an image on the button then click on the "AddNewOrder" method from the GUI click property and choose the image link.


Image 4.


Image 5.

Now import an image from your local system.


Image 6.

Now click on the method property and see that there are two events available.


Image 7.

Click on "Edit Execute Code" and write this code:

partial void

// Write your code here.


Now hit F5 to see the output.


Image 8.

You will see on the screen a new button with an image. Now click on this image, it will redirect you to create a new order screen.


Image 9.