RIA Development Center
Features Tips Events
Jon Galloway discusses the challenges and solutions to handling keyboard input in Silverlight including:
  • Silverlight not firing the KeyDown event for cursor (arrow) keys
  • The difference between Key and PlatformKey
  • The missing Key Enumeration
  • How to create a keyboard handler event
  • Read more
    See more tips
    Get regular email alerts when we publish new features!
    DevX RIA Development Update

    More Newsletters
    Get Started with Silverlight Using Visual Studio 2008 and Expression Blend 2 (cont'd)
    More Resources
  • MSDN: Microsoft Visual Studio 2008
        Downloads
  • Free Trial: Microsoft Expression Blend 2
  • Getting Started
    With all the necessary tools installed, you can now create your first Silverlight application. Launch Visual Studio 2008 and create a new project. In the Project types, select Silverlight and then select the Silverlight Project template (see Figure 1). Name the project OurFirstSilverlightProject.


    Figure 1. First Step: Creating a new Silverlight project.
     
    Figure 2. The Foundation: All the basic files contained within the Silverlight project.

    In the Solution Explorer, click the Show All Files button to reveal all the files that Visual Studio has added for the project. Figure 2 shows the files contained within it.

    The following sections explain the basic files contained within a Silverlight project.

    TestPage.html
    This is a test page that you will use to test your Silverlight application. It contains the Silverlight control and references two JavaScript files—Silverlight.js and TestPage.html.js (their uses are explained in the next section). Listing 1 shows the content of TestPage.html.

    HTML pages that host Silverlight controls can also contain other normal HTML elements that make up a web page. When you double-click on the TestPage.html file in Solution Explorer, Visual Studio 2008 will display the page in Split view, a new feature available in Visual Studio 2008. Using the Split view, you can view the HTML code and at the same time preview how it looks in a browser (see Figure 3).

    Figure 3. Test Case: Displaying an HTML page in Split view.

    TestPage.html.js
    This file contains one JavaScript function that loads the Silverlight control onto the page. It also references the XAML file that contains the UI of your Silverlight application (Listing 2).

    Each HTML page should have a corresponding JavaScript (.js) file that loads the Silverlight control contained in a relevant XAML File.

    Page.xaml
    This file contains the UI for your Silverlight application. Listing 3 shows the default content created by Visual Studio 2008.

    Take note here of the x:Class attribute. In Listing 3, it specifies that the code-behind Class name is OurFirstSilverlightProject.Page (OurFirstSilverlightProject is the default root namespace of our project while Page is the class name), and its corresponding assembly is located in ClientBin/OurFirstSilverlightProject.dll.

    Visual Studio 2008 provides IntelliSense support for XAML content, which is quite a handy feature if you're considering writing XAML manually.

    Page.xaml.vb
    This file contains the managed source code of our Silverlight application. The default class name used by Visual Studio 2008 is Page (Listing 4).

    The Page.xaml.vb file is where you write your managed code. When a Silverlight application is ready for deployment, only the compiled assembly needs to be deployed. There is no need to deploy the source code.

    Silverlight.js
    This is the file provided by Microsoft that creates all the necessary plumbing needed to ensure that the target Web browser is able to run your Silverlight applications. By including this file in your application, the target Web browser will be asked to download the necessary runtime if the Silverlight runtime is not installed (every Silverlight application must include this file). Under the License Agreement, you are not allowed to modify this file. For Web servers that serve multiple Silverlight applications, you can simply put a single copy of this file in one location and set all the pages containing Silverlight content to point to this page.

    Page 3 of 7
    Previous Page: Obtaining the Tools Next Page: Building the User Interface Using XAML
    Page 1: IntroductionPage 5: Writing the Logic Using Visual Basic
    Page 2: Obtaining the ToolsPage 6: Transformation
    Page 3: Getting StartedPage 7: Deploying Silverlight Applications
    Page 4: Building the User Interface Using XAML 
    Want to know who achieved gaming stardom? Keep checking RIGHT HERE! In the upcoming weeks, we will be showcasing some of the hottest next-gen games using Silverlight 2. You will be able to play them, too! Winners will be announced on June 30, 2008 so be sure to tune in. Happy Gaming!