.Microsoft Silverlight

Microsoft announced the end of life of Silverlight 5 in 2012. In 2013, Microsoft announced that they had ceased development of Silverlight except for patches and bugfixes. Microsoft has set the support end date for Silverlight 5 to be October 2021. Silverlight is no longer supported in Google Chrome since September 2015. Microsoft Edge does not support plugins, so it does not support Silverlight.

Silverlight is Microsoft's .NET-based framework for building applications that run inside a Web browser. More recently, a specialized version called "Silverlight for Windows Phone" is one of the development environments used with Microsoft's Windows Phone. Silverlight 1 was initially released in September 2007 as a plug-in for web browsers with functionality similar to Adobe Flash. Silverlight evolved and gained more capabilities with each new release. Silverlight 5 supports elevated-trust and Out-Of-Browser applications, XAML-based controls, printing, 3-D graphics, and various methods of network and local file access.

Silverlight's framework varies for the different environments. For example, Silverlight for Windows Phone contains additional support for touch input, and does not contain support for the HTML DOM bridge. As a cross-browser plugin, Silverlight works with the newer releases of the major browsers running on Windows (IE, Firefox, Chrome, Opera, Safari). Silverlight supports the fundamental concepts of .NET which includes a scaled-down version of the CLR that allows client-side code to be written in C#.

Silverlight Version Release Date Version Features and Release History
Silverlight 1 September 2007 Mainly enhanced media support using JavaScript
Silverlight 2 October 2008 .NET framework subset added (CLR and .NET languages) and XAML UI
Silverlight 3 July 2009 Out-of-Browser (OOB) support, navigation framework, additional controls, 3-D graphics
Silverlight 4 April 2010 Printing support, OOB explicit "trust" status, implicit theming, enhanced tooling in VS 2010
Silverlight 5 April 2011 Various performance improvements, full-trust in-browser, better MVVM support.

Silverlight Releases

Silverlight's capabilities have continued to increased since it debut in 2007:

  • Silverlight 1 started as a browser plugin (like Adobe Flash), that contained limited technology such as 2-D graphics and media playback support. Silverlight 1 required developers to code in JavaScript.

  • Silverlight 2 included major enhancements which included a limited CLR, portions of the .NET framework, and a user interface model based on Windows Presentation Framework (ie XAML).

  • Silverlight 3 added support for Out-of-Browser (OOB) applications, a navigation system, additional controls, enhanced binding, perspective 3-D graphics.

  • Silverlight 4 added more capabilities to OOB applications by elevating their trust level, comprehensive printing support independent of screen content, implicit theming by element type, and file drag-and-drop capabilities. Also enhanced tooling support for Silverlight in Visual Studio 2010.

  • Silverlight 5 added multiple window support for OOB, performance improvements in various areas (networking, parsing, graphics), full-trust in-browser, and enhancements in data binding. As of 9/29/2013, the latest version of Silverlight is Silverlight 5 Build 5.1.20513.0 released July 9, 2013. Check Silverlight Release History for newer releases.

  • Silverlight for Windows Phone is the most recent additional usage for Silverlight. For this version of Silverlight see Silverlight for Windows Phone.

Silverlight and Windows Presentation Foundation

"Silverlight and Windows Presentation Foundation (WPF), share similar design concepts. WPF was part of .NET 3.0 and introduced the use of XAML in creating user interfaces. It also introduced other concepts which are now used by Silverlight."

  • Microsoft compares Silverlight and WPF in the article Contrasting Silverlight and WPF. The article notes that while Silverlight and WPF share many features and capabilities, subtle --and not so subtle -- differences exist between the two platforms.

  • Microsoft has suggestions for Multi-Targeting in developing applications to run on both Silverlight and WPF.

  • While Silverlight is considered a subset of WPF, there has been new functionality released in Silverlight which was later integrated into WPF (e.g. Visual State Manager)."

Silverlight 5.0 Capabilities

"Silverlight includes support for HTTP over TCP. You can connect to WCF, SOAP, or ASP.NET AJAX services and receive XML, JSON, or RSS data. In addition, you can build multicast clients with Silverlight"

  • Silverlight controls such as DataGrid and ListBox can work with data objects.. Data Binding can be used to tie the controls directly to the data. You can bind data object to controls so that updates performed in the user controls are automatically propagate back to the data source.

  • Silverlight provides network capabilities such as the WebClient class, which can download content to the client. WebClient can also be used to send and receive plain XML messages. Silverlight applications can also access Web services such as Windows Communication Foundation (WCF), SOAP, and ASP.NET AJAX.

  • Silverlight graphics can use drawing, shapes, paths, and complex geometries. Areas defined by geometries can be filled with effects, such as images, color gradients, or video clips, by using brushes. For more information, see Shapes and Drawing, Geometries, and Brushes. You can transform graphics and other objects on the screen (e.g. rotate or skew). You can even apply 3D effects. See Transforms and 3-D Effects (Perspective Transforms). Silverlight also includes Deep Zoom, which allows you to easily zoom and pan large detailed images. For more information, see Imaging and Deep Zoom.

  • In addition to static graphics, you can add animations, audio, and video to your application to make it more dynamic and interactive. For more information, see Animation Overview and Audio and Video Overview.

  • Silverlight also contains: isolated storage, asynchronous programming, file management, HTML DOM interaction, serialization (JSON and XML), and XML libraries (XmlReader and XmlWriter classes). Note: While ASP.NET is the default server-side content, Silverlight is not dependent upon any particular server side technology.

Silverlight Development

"Silverlight applications are developed in Visual Studio. Many new libraries are available for import into Visual Studio (like the Silverlight toolkit) through the use of the integrated NuGet package mananger. Additional development tools include Expression Blend (design-centric capabilities), Expression Encoder (video transcoding and editing) and Deep Zoom Composer (image zooming). "

  • Visual Studio 2012 includes support for Silverlight 4 and Silverlight 5.

  • Visual Studio 2010 Service Pack 1 includes support for Silverlight 3 and Silverlight 4. To use Silverlight 5 with VS 2010, install Silverlight 5 Tools for Visual Studio 2010

  • Additional Silverlight tools are in the "Silverlight Toolkit" available through NuGet or from Microsoft's open source website (Codeplex - Silverlight Toolkit. When working with Windows Phone, additional Silverlight tools are in the "Windows Phone Toolkit" available from Microsoft's open source website (Codeplex). The Toolkit is on a shorter release cycle than the SDKs. Datepicker and other advanced controls are only in the Toolkit.

  • Visual Studio supports two types of Silverlight website solutions:
    1. Ordinary Website with HTML Pages - using a Stand-Alone Silverlight Solution
      • The Silverlight application is embedded in an HTML file.
      • Visual Studio creates one project (just the Silverlight application project) in the solution.
      • Uncheck the option to "Host the Silverlight application in a new Web site" when creating the solution.
      • This simple type of solution will work for many applications, but does have some limitations. It will NOT support creating web services and it does NOT support ASP.NET web controls.
    2. ASP.NET Website - using an ASP.NET-Hosted Silverlight Solution
      • The Silverlight application can be embedded in an HTML file or in an ASP.NET web page.
      • Visual Studio creates two projects (Silverlight application project and website hosting project) in the solution.
      • Check the option to "Host the Silverlight application in a new Web site" when creating the solution (It should be checked by default).
      • This is a more complex type of solution which is required in some situations, such as developing web services or using ASP.NET web controls.
    3. Stand-Alone Silverlight Solution

Stand-Alone Silverlight Solution

When creating a new solution in Visual Studio, you are given the option to "Host the Silverlight application in a new Web site". This option is selected by default. Unselect this option to create a single project just for the Silverlight application.

The Silverlight application project is created with a the following set of essential files:

App.xaml - resources placed in this file will be global to the entire application.

App.xaml.cs - contains the application lifecycle events (startup and exit), the unhandled exception event, and specifies the startup object (defaults to MainPage).

MainPage.xaml - defines the first page of the user interface. This includes the elements and controls. Note: Silverlight defines elements as things which appear in the display window and corresponds to a .NET class. Controls are defined as things which appear in the display window and allow for user interaction (eg. TextBox = control; TextBlock = element).

MainPage.xaml.cs - contains the code for the partial class that defines the first page of the user-interface. Referred to as the "code-behind" for the MainPage.xaml file. The file contains initialization code and the code for event handlers.

AppManifest.xml - is the Silverlight manifest file and describes the application to the Silverlight runtime engine. The Silverlight manifest file is automatically generated and rarely needs to be edited by hand.

AssemblyInfo.cs - contains general information (eg. version, description, etc.) about the application assembly (eg. .exe or .dll files). Some of this information will show when you right-click on the assembly file, in Windows file explorer, and view the details of the file properties.

In a stand-alone Silverlight solution, the compiled .xap file resides under the project's "Bin" folder, in the "Debug" or "Release" subfolder (depending upon the project build type).

ASP.NET-Hosted Silverlight Solution
ASP.NET-Hosted Silverlight Solution

When creating a new solution in Visual Studio, you are given the option to "Host the Silverlight application in a new Web site". This option is selected by default. Leave this option selected to create two projects. The first project is for the Silverlight application (as is used by the stand-alone Silverlight solution) and the second project is for the ASP.NET website which can host the Silverlight application.

The website project contains an .html and an .aspx versions of test pages for hosting the compiled Silverlight application. The .aspx page is the default and is used for Internet Information Services (IIS) running ASP.NET. The .html page can be used if hosting on another HTTP server (eg Apache).

The website project also contains a Silverlight.js file which contains JavaScript helper functions for creating the Silverlight content region.

In an ASP.NET-hosted solution, the compiled .xap file resides under the project's "Bin" folder, in the "Debug" or "Release" subfolder (depending upon the project build type) and the compiled .xap file is also copied to the "ClientBin" folder under the Web project.

In an ASP.NET-hosted solution, the Web project is the default startup project (notice it is highlighted). This tells Visual Studio to use the built-in test web server when launching the application. The built-in test server functions as a simple IIS, but it will only respond to requests from the local computer.

A compiled Silverlight application will end up as a .xap file. The "zap" file is actually a ZIP file renamed. The .xap file contains everything needed to deploy the Silverlight application. The .xap file contains the compiled code in the form of a DLL file, other assemblies used by the application, the Silverlight manifest file, and other resources (images, etc).

.Unzipped .xap File

The ".xap" File is Actually a ".zip" File Renamed

A browser will need to download the .xap file to the client computer to execute it. If the size of the .xap file is an issue, you can use the "application library caching" option (aka assembly caching). When used instead of packing the .dll files into the .zap file -- it instead zips them into individual files alongside the .xap. Assembly caching can greatly reduce the size of the .xap file and provide faster initial loading of the application.

Silverlight Deployment

"Silverlight can be integrated with HTML by either using the HTML object tag or JavaScript. The object tag is the simplest, and the recommended way to embed the Silverlight application."

  • In order to support Silverlight-based applications, your Web server must be configured to associate the .xap file name extension with the MIME type "application/x-silverlight-app". For IIS 7.0 or later, this value is pre-configured.

  • Silverlight can be integrated with HTML by either using the object tag or JavaScript helper files (Silverlight.js). The HTML object element is the simplest way to embed the Silverlight plug-in, and is the recommended way. This is the default approach that is used by Visual Studio when you create a new Silverlight-based application and choose to host it in a dynamically generated HTML page. In Silverlight 1 JavaScript was the only way to integrate Silverlight with HTML. In current versions JavaScript may still be used to load splash screens.

  • Note: Previous versions of the Silverlight SDK included the ASP.NET Controls for Silverlight. These enabled a way for Silverlight applications to be embedded in an ASP.NET Web page that is familiar to ASP.NET developers. The Silverlight SDK no longer contains the ASP.NET Server Controls for Silverlight and developers are encouraged to use the HTML or JavaScript embedding techniques.

  • The object tag method is the easiest way to add Silverlight to HTML:

        <div id="silverlightControlHost">
            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
                     <param name="source" value="ClientBin/Mars.xap"/>
                     <param name="onError" value="onSilverlightError" />
                     <param name="background" value="white" />
                     <param name="minRuntimeVersion" value="5.0.61118.0" />
                     <param name="autoUpgrade" value="true" />
                     <a href="" style="text-decoration:none">
                             <img src="" alt="Get Microsoft Silverlight" style="border-style:none"/>
               </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

  • The four required attributes of the object tag are: data, type, width/height, and source parm.

  • If the browser fails to display the Silverlight application, it will fall back to the content inside the object tag. You may modify the fall back content. By default the fallback content will display the following image which provides a link for installing Silverlight.
.Silverlight Fall Back Screen

The Fallback Image Provides a Link for Installing Silverlight