Getting Started with Silverlight for Windows Embedded (Compact 7)


This tutorial describes how to create and modify a Microsoft Silverlight for Windows Embedded application by using the following tasks:

  • Create a Silverlight for Windows Embedded application template from a sample Microsoft Expression Blend 3 project
  • Add C++ code to the template to create a functioning application
  • Add event handlers to the application using the Windows Embedded Silverlight Tools event handler viewer
  • Update the application using an updated version of the Expression Blend project

Windows Embedded Silverlight Tools is a plug-in for Visual Studio 2008 SP1 that helps you convert Expression Blend Silverlight for Windows Embedded projects into native (C++) Windows Embedded Compact applications. These tools are useful if you use Expression Blend to create the XAML markup that defines the user interface (UI) of your application.

The Silverlight for Windows Embedded Platform Builder Subproject Application Wizard walks you through the steps for creating a template Platform Builder subproject from the XAML (eXtensible Application Markup Language) and resource files of an Expression Blend project. Starting with this generated template, you can add functionality to create a native Windows Embedded Compact application that has a Silverlight for Windows Embedded UI designed in Expression Blend.

When you are ready to create event handlers for your Silverlight for Windows Embedded UI objects, the Windows Embedded Events view allows you to select objects and events (such as KeyDown and MouseLeftButtonDown) to associate with those objects, automatically generating C++ stub event handlers when you add new events.

You can later modify your Silverlight for Windows Embedded project in Expression Blend and then merge these changes into your Platform Builder subproject using the Windows Embedded Silverlight Tools update tool. Windows Embedded Silverlight Tools automates the process of using Expression Blend files to create Silverlight for Windows Embedded-based Windows Embedded Compact applications. This automation eliminates difficult and time-consuming tasks, diminishes the likelihood of introducing human error, and frees you to focus on the business logic of your application. The ability to merge UI updates during and after application development makes it possible for the designer and the developer to work on an application in parallel, so the application can be finished more quickly.

When a designer creates graphics, animations, and UI elements in Expression Blend, the resulting Expression Blend project contains XAML files that describe the visual components and UI characteristics of an application. However, these XAML files may include elements that Silverlight for Windows Embedded does not support. For each of these XAML files, Expression Blend generates a .NET code-behind file that may contain C# application code. However, because Windows Embedded Compact applications must be written in C++ to use the Windows Embedded Compact native Silverlight for Windows Embedded runtime, you cannot use these Expression Blend-generated code-behind files as an application template. To use an Expression Blend project as the basis for a Windows Embedded Compact application, you need some way to convert Expression Blend project files to the tools and native runtime of Windows Embedded Compact.

Windows Embedded Silverlight Tools bridges this gap between the Expression Blend project and the Windows Embedded Compact development environment by providing features that do the following:

  • Verify incoming XAML files for use with Silverlight for Windows Embedded, locating and reporting any unsupported elements.
  • Automatically generate template application C++ code from XAML source files.
  • Provide a way to easily select objects, hook up events, and add event handlers to your Expression Blend-derived application.
  • Automatically identify changes in the Expression Blend project and propagate these changes to your application’s project resource files.

Without Windows Embedded Silverlight Tools, you would have to manually parse each incoming XAML file to identify and remove unsupported elements. For large Expression Blend projects, this porting task could be a tedious and error-prone process. Since the code-behind files that Expression Blend generates are not suitable for use with Windows Embedded Compact, you would have to manually write your own complex application code to manage the Silverlight for Windows Embedded runtime and attach event handlers to XAML objects. When the designer makes changes to the source Expression Blend project, you would have to manually find and merge these changes into your application project. Windows Embedded Silverlight Tools merges Expression Blend project updates with a mouse click, making all of these tasks unnecessary.

Although Windows Embedded Silverlight Tools provides many capabilities for accelerating your application development, it does have several limitations:

  • It does not create XAML files.
  • It does not generate managed source code. It only generates C++ code to use with Windows Embedded Compact.
  • It does not generate C++ code for the following XAML elements or their child elements:
    • ControlTemplate
    • DataTemplate
    • FrameworkTemplate
    • ItemsPanelTemplate
    • MediaElement
    • Resources
    • RenderTransform
    • Storyboard
    • Style
    • VisualState
    • VisualStateGroups
  • It does not support custom controls; therefore, you must manually register any custom controls in your application. For more information about custom controls, see the section titled " Create a Custom User Control in Silverlight for Windows Embedded" in Silverlight for Windows Embedded Developer's Guide.
  • It does not handle manual modifications that you make to your Silverlight for Windows Embedded project outside of Expression Blend.

Windows Embedded Silverlight Tools is not a replacement for Expression Blend, Visual Studio, or Platform Builder; it complements these tools by providing an efficient way to use Expression Blend project files as the basis for Windows Embedded Compact applications. For this reason, Windows Embedded Silverlight Tools does not offer overlapping functionality that is already available in these other tools.

Typically, a designer creates a Silverlight for Windows Embedded-based UI project in Expression Blend and passes it to a developer. The developer, in turn, creates a Windows Embedded Compact application from the project. Using resources from the Expression Blend project, the developer writes and tests the code that implements the functionality of the application. To enable the designer and developer to work on the application in parallel, they create a Designer/Developer contract that defines the interface between the UI and the business logic of the application. If the designer and the developer properly follow this contract, they can assemble the XAML from the Expression Blend project and the C++ files from the developer at any time to view the current state of the application.

Windows Embedded Silverlight Tools works on the assumption that you and your designer are developing your application according to a Designer/Developer contract, and that there is a clearly defined interface between the UI and the application implementation. For more information about this development process and the Designer/Developer contract, see Designer and Developer Workflow in Silverlight for Windows Embedded.

Windows Embedded Silverlight Tools provides support for three common Silverlight for Windows Embedded development tasks:

  • Generating an application template from an Expression Blend project
  • Adding event handlers
  • Updating your application with changes made to the Expression Blend project

Each of these tasks is described in this article, with tutorial examples that demonstrate how Windows Embedded Silverlight Tools can help you quickly create Silverlight for Windows Embedded-based applications for Windows Embedded Compact.