Lately has been much talked about Silverlight, the commitment of Microsoft to compete with Macromedia's Flash. The first version of Silverlight was based heavily on the use of javascript and deploy very complex applications that were relatively complicated. Version 2 of Silverlight this whole paradigm has changed because the capacity was utilized. NET to develop Silverlight 2 applications. Now we can use C # for Silverlight development, and have a set of controls that help us much in development. In this tutorial I will explain how to create a simple application in Silverlight 2, to accommodate to this new platform.
What is Silverlight 2.0
The Silverlight 2.0 is a platform that allows us to develop rich applications for the Internet (RIAS - Rich Internet Applications). As the flash, you must also install a plugin in the browser to run Silverlight applications. This small plugin contains a reduced version of the platform. NET.
The capabilities of Silverlight 2.0 is huge and will play videos from high quality to the construction of complex applications, such as an application of analysis of the stock market. Silverlight applications using a language called XAML. It is with this language that we will define the interface of our Silverlight application. The logic of the application (code-behind) can be built using C # or VB.
Tutorial - Hello Silverlight 2.0
Now we have an idea of what is Silverlight 2.0, we will continue with the tutorial, where we create an application like "Hello World!".
Before we start with the tutorial itself, we need to have our development environment, ready to develop Silverlight 2.0 applications. For this there are some prerequisites:
To develop Silverlight 2.0 applications need a computer with Visual Studio 2008 and the Silverlight Tools installed. You can check this article to know how to install the Silverlight Tools:
Microsoft Expression Blend and Deep Zoom Composer are optional components, are not necessary for the scope of this tutorial, but may investigate them if they want to build more complex applications.
Assuming that all components are already installed we start the tutorial, open the Visual Studio 2008 and creating a new Silverlight project type.
When you create a new project of type Silverlight 2.0, we asked if we want to create a web project to host / test the project Silverligth. For this tutorial we will say yes, and we want a web project of type "Web Application".
As we can see the next picture, our solution is a web application, where our project will be hosted Silverlight, Silverlight and the project itself. The Silverlight project is forming two XAML page, the App.xaml and Page.xaml.
For this tutorial we will just focus on us Page.xaml, which is the default which is open on the desktop when you create the solution.
At the bottom of Visual Studio, we have the XAML code of our Silverlight, which initially consists of a UserControl and a grid-type layout. Within the Grid we will create a button by adding the following code:
The attribute x: Name indicates the name of the button, the Width indicates the width, height Height and Content is the text that appears on the button.

Today we have our button created. If they want may be the solution, and we will see the button. We already have the button, we now add the click event to change your text where you clicked. To this we add an attribute to the button:

When we add the attribute click the Visual Studio 2008 gives us the option to immediately associate an Event Handler for the Click event, if we simply click on the Enter key. When you click Enter, Visual Studio creates the Event Handler in the Codebehind Page.xaml.

We then move to the Codebehind of the page, right-clicking the mouse on the area of design and choosing the option "View Code". In the Codebehind, we have the function btnHello_Click.

On the basis of the click of the button, we will create the logic to change the text of the same, each time it is clicked. adding the following code:

If we run the application when you click the button, the text will alternate between "Click here" and "Hello Silverlight 2."

We built our first Silverlight application, quickly and easily, including the use of events, with all the convenience of the platform. NET C #. ![]()
NOTE: For the web application is only downloaded a xap file that can find the application folder ClientBin Web
If you have any questions or concerns leave comment below.
If you liked this article subscribe to the RSS feed istomesmo to stay updated on the latest articles.
Learn more about RSS fedde here
Articles that may interest you:




May 16th, 2008 at 22:37
I like the Silverlight. Flash is yet to be long, but programming in C # instead of ActionScript is another level ...
To see the power of the SL just see this: http://memorabilia.hardrock.com/
May 29th, 2008 at 4:14
I like Flash but Silverlight does not want to ... .. congratulations for the tutorial ...
August 4th, 2008 at 23:26
@ Pasokon
The Silverlight is still at an early stage. Has great potential, but we see it not appeared too late. The flash is very implemented.
August 4th, 2008 at 23:28
Artur @
I fully agree. The example gives really great to see the potential of silverlight. And the convenience of programming with C # can be decisive in the evolution of Silverlight to the Flash. Let's see. Only time can tell us who is the winner. If he is going to be one.
May 14th, 2009 at 0:18
man earned the intro, it is nice to see that this new technology will burst.
June 16th, 2009 at 18:37
Great tutorial, great investment with the Microsoft Silverlight agree more with the "ndoCosta" the flash is very implemented.