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.

img1.jpg

Image 1.

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

img2.jpg

Image 2.

You will see that a new method has been added.

img3.jpg

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.

img4.jpg

Image 4.

img5.png

Image 5.

Now import an image from your local system.

img6.jpg

Image 6.

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

img7.jpg

Image 7.

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

partial void
       
AddNewOrder_Execute(){

           
// Write your code here.
           
this.Application.ShowCreateNewOrder();

        }


Now hit F5 to see the output.

img8.jpg

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.

img9.jpg

Image 9.
 


Similar Articles