In this article you will learn how to use commands as buttons and links in LightSwitch 2012.
Getting Started
- Open Visual Studio 2012.
- Go to "File" => "New" => "Project..."
- Select "LightSwitch" in installed templates.
- Select "LightSwitch Application (Visual C#)".
- Enter the Name and choose the location.
- 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
AddNewOrder_Execute(){
// Write your code here.
this.Application.ShowCreateNewOrder();
}
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.