In this tutorial I will tell you, how to create your first Silverlight application with the help of visual studio 2010 IDE.

Prerequisite
  •    Visual Studio 2010 IDE
  •    Silverlight 3.0 or 4.0
For creating first Silverlight application follow these steps
  •    Open visual studio 2010.
  •    Go to File menu followed by New and click it. After performing this step a new project dialog box is open.

Silverlight application

 

  •  From installed template select Silverlight and from project template Silverlight application.
  • In name box provide your application name such as FirstSilverLightApplicationDemo and choose the location of your application and then click OK button.

Silverlight application

 

  • After clicking OK button a new dialog box opens which ask some additional behavior about your application. Don’t change default settings and simply click OK button.

Silverlight application

 

  •  After clicking OK button a new window is open whose name is MainPage.xaml. You have to perform all the activities on this page.
  • Every Silverlight application consists of XAML markup code and C# or any .NET language code for implementing behavior.
Write down the following code in XAML window
<Button Content="Silverlight Application Demo" Height="28" HorizontalAlignment="Left" Margin="68,128,0,0" Name="btnDemo" VerticalAlignment="Top" Width="249" />
These code snippets create a Button control. Double click on Button control and code behind file open. Write down following code.
private void btnDemo_Click(object sender, RoutedEventArgs e)
{
            MessageBox.Show("Hello Dear! Welcome to first demonstration of Silverlight Application.");
}

 

For executing application press CTRL+F5.

Output of the following code snippet is as follows

Silverlight application

 

When user click the button object then a dialog box opens which shows some message to user.

Silverlight application


Leave Comment