Tuesday, July 13, 2010

Create a simple SilverLight Application

This tutorial will show you how to create a simple Silverlight Application. 

Many thanks to my friend Hassan-Mia Salie for his contributions.

   • Visual Studio 2008 SP1
   • Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1
       Available for download here
       The package will install the following components:
        Silverlight 3 developer runtime
        Silverlight 3 software development kit
        Silverlight 3 Tools for Visual Studio 2008 SP1

Create the Silverlight Application
• Launch VS2008
• Create new project --> Visual C# --> Silverlight --> Silverlight Application 

Select the following:

The following components are automatically added to the solution.

Open MainPage.xaml in design view:

 <UserControl x:Class="MySilverLightApp.MainPage"
          mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">

Add code in the Grid section.
 <Button Name="cmdHello" Content="Click to view time." Width="200" Height="40" Click="Button_Click"></Button>

 Open MainPage.xaml.cs
Add the following:
cmdHello.Content = System.DateTime.Now.TimeOfDay.ToString();
private void Button_Click(object sender, RoutedEventArgs e)
   cmdHello.Content = System.DateTime.Now.TimeOfDay.ToString();
Build the solution.
Right click on MySilverLightAppTestPage.aspx and select “View in browser”


Open the Bin\Debug folder and see the output:
  • AppManifest.xaml
  • MySilverLightApp.dll
  • MySilverLightApp.pdb
  • MySilverLightApp.xap
  • TestPage.html


Post a Comment