Dec 20, 2011

Creating a Simple Silverlight Application in Microsoft Visual Studio 2010

In the previous article ,we have discussed about the basics of Silverlight and In this article, we will discuss how to create a simple silverlight application using Microsoft Visual Studio 2010.
Go to Visual Studio File ->New Project
                                           
Select Visual C# in projects -> Silverlight Application (I have used .Net Framework 4.0)
Now, you will see a pop-up window like this
This windows gives the options for the user to create a new web application within the solution so that, we can test the silverlight application created here.
Here in our project, SampleSilverlightApplication.web is the web application created and we also select the silverlight version here.
Once clicked OK, a new silverlight application will be created as shown below
You will two projects created in the solution one is to design and code the application and the other is to test the application.
MainPage.xaml contains the design part of the application and MainPage.xaml.cs is the code behind where you will write the business logic.
In the right side, you will see the ToolBox which consists of Silverlight Controls which you can use for designing the application.
Now drag and drop a Label and Button in the design part and Right Click on the control -> Properties to view the properties of the control


I have changed the properties of label and button

In the .cs file, you will see the NameSpaces for the silverlight application in specific has been added.
Now, we will write the code behind for the button event as
Private void button1_click (object sender, EventArgs e)
{
MessageBox.Show(“This is a simple silverlight Application”);
}

Now save the code and debug the application. The application will render in the web application created in the initial steps.

Important Note: Once you debug the code, you will find solution package with the extension .xap in the Client Bin folder which is present in the Web Application.

This package consists of all the functionalities which is created in the application. 
When you click on the “Click this” button you will see a MessageBox pop-up with the message showing message “This is a simple silverlight Application”





That’s it we have learned how to create a simple silverlight application using Microsoft Visual Studio 2010.
See also, how to deploy the created silverlight application SharePoint 2010 in this article.
The full code can be downloaded from here.

0 comments:

Post a Comment

Dear Readers,

I LOVE to hear from you! Your feedback is always appreciated. I will try to reply to your query as soon as possible.

1. Make sure to click the "Notify me" check box at the right side to be notified of follow up comments and replies.
2. Please Do Not Spam - Spam comments will be deleted immediately upon review.