Wednesday, February 27, 2008

Getting Started with Silverlight 1.1 and Visual Studio .Net 2008

Install the necessary components.

  1. Install the Windows Silverlight 1.1 Runtime from here: http://www.microsoft.com/silverlight/resources/LicenseWinDev.aspx
  2. Install the Microsoft Silverlight 1.1 Tools Alpha for Visual Studio 2008 from here: http://www.microsoft.com/downloads/details.aspx?familyid=25144c27-6514-4ad4-8bcb-e2e051416e03&displaylang=en
  3. Install VS.NET 2008.

Create a Silverlight VS.NET 2008 project.

  1. Startup VS.NET 2008.
  2. Click on File->New->Project.
  3. Under Visual C#, click on the Silverlight node.
  4. Select the Silverlight Project project.
  5. Click on OK.
  6. Double click on the Page.xaml XAML file in the Solution Explorer.
  7. Between the Canvas XML elements, type in the following XAML code: <TextBlock x:Name="txtHelloWorld" MouseLeftButtonDown="txtHelloWorld_Click"> Hello World! Click here.</TextBlock>
  8. Double click the Page.xaml.cs file in the Solution Explorer.
  9. Add the following event handler method: <TextBlock x:Name="txtHelloWorld" MouseLeftButtonDown="txtHelloWorld_Click"> Hello World! Click here.</TextBlock>
  10. Save all changes.
  11. Test the Silverlight application by right-clicking on the TestPage.html file in the Solution Explorer and clicking on View in Browser, then click on the text--it should respond to the event.

Discussion

The JavaScript code in the TestPage.Html.js file is responsible for actually rendering the Silverlight content in the client's browser. This is done by calling the createSilverlight() JavaScript function from within the TestPage.Html page. The JavaScript code in the Silverlight.js file checks if Silverlight is installed and redirects the user to install if chosen to do so.

Please note that this Silverlight project does not incorporate ASP.NET functionality/content, only basic HTML content. In order to create an ASP.NET website that makes use of Silverlight functionality, please refer to my article titled "Creating a Silverlight-AJAX-Enabled Web Site with Silverlight 1.1 and VS.NET 2008".

No comments: