The web gets closer to the desktop. Case study: WPF and Silverlight

Dec 21, 2010

Windows Presentation Foundation, known as WPF, is a Microsoft development platform for building (mostly) rich desktop applications. On the other hand, Silverlight is a framework (provided by Microsoft) that facilitates the development of rich internet applications, with complex multimedia features, such as streaming and animations.

If until now programmers were focused on the competition between Silverlight and Adobe Flash, now the point of interest has shifted to the battle between desktop vs. web applications, and in our article, between WPF vs. Silverlight. If some are hurrying to declare WPF as obsolete, claiming that cloud computing and web applications will dominate the market of the future, Microsoft is not ready to stop the development process for WPF and still has some cards hidden in its sleeve.

Shipped as part of the .NET Framework, the latest version of WPF (WPF 4) was released on April 2010, and brings important improvements in terms of graphics and controls. It's important to mention that, although WPF is used for developing Windows applications, it is also capable of running hosted web applications thanks to the XBAP (XAML Browser Application). A minus of WPF would be that it runs exclusively on Windows machines: Windows XP, Windows Server 2003, Windows Vista, and Windows Server 2008.

Released at the same time as WPF 4, Silverlight 4 is focused on building powerful business applications "on the web". More independent than WPF, Silverlight runs mainly in web browsers, such as: IE, Firefox and Safari, and is compatible with Windows, Mac and also Linux OS (via Moonlight). Although Silverlight is considered to be a "subset of WPF", Silverlight 4 proves to be more than that, extending its capabilities beyond the browser into the desktop. Features such as "Offline DRM" (adds the possibility for Silverlight DRM to work offline), "UI control" (which allows to control parts of UI: "start position, size and chrome") and "run desktop programs" (such as Office) make Silverlight to appear that it's offering the best out of the two worlds.

If until now we've seen the surface differences between WPF and Silverlight, now it's time to go in more depth and see the architectural discrepancies.

One of the most important differences is that Silverlight is a downloadable plug-in (running within a browser) and has access only to a subset of the full .NET Framework (called CoreCLR), while WPF has access to the main .Net Framework and its entire associated tools. As a result, this triggers numerous discrepancies between the two:
* WPF apps run mainly on a Windows client platform (make an exception the browser-hosted applications), while Silverlight runs mostly in web browsers (Silverlight 3 brought about the OOB extension which allows developers to write out-of-browsers apps)
* WPF apps have the possibility to access local file resources, while Silverlight has limited access
* WPF supports all the fonts found in the Windows OS, but Silverlight natively supports only a few fonts (Note: Silverlight contains a default font, used when no other font is selected, called "Portable User Interface.")
* WPF supports the creation of custom routed events (via the EventManager helper class). Silverlight doesn't support custom routed events.
* WPF supports all types of routed events: direct, bubbling and tunneling, but Silverlight only supports direct and bubbling events.
* Regarding data-binding (the mechanism of associating data to controls), WPF supports four binding modes (One-Way, Two-Way, One-Time, One-Way To Source) and Silverlight only three - minus the One-Way To Source mode.
* Regarding networking: Silverlight can only make asynchronous network requests (a synchronous call may block the main UI thread). On the other hand, WPF has no restrictions, and has full access to the networking features in .NET Framework.
* Although, WPF and Silverlight share a large part of XAML language, the former benefits from some extra XAML elements, such as "Styles".
* Concerning the printing functionality, although previous versions of Silverlight didn't support this, Silverlight 4 brings in the possibility to print documents, reports, charts, and also allows a "virtual print view".
* WPF supports an extensive range of 3D features: animation, cameras, materials, lights, models, transformations etc.. Silverlight 3 brought improvements in terms of  3D graphic and animation support such as: "Pixel Shader effects", "New Bitmap API", and spring and bounce animation effects.
Although there are a lot of core differences between WPF and Silverlight, Microsoft tries to bring the two technology closer, with each new version it releases. In order to ease the code reusing process, Silverlight and WPF share a number of elements, such as: Data Binding, Animation, Dependency Properties and Custom Controls. Also, both technologies support vector-based drawing elements, resource
dictionaries (Silverlight supports only static resources, while WPF supports both static and dynamic resources).

Note: Dynamic resources are a type of resource that is evaluated each time it is accessed.

So, in terms of desktop vs. web applications, neither WPF nor Silverlight has a clear victory, because both Microsoft technologies offer plenty of advantages, which can be regarded as disadvantages when you are not using the right tool for your application. However, one thing is certain: both WPF and Silverlight offer the Microsoft proven experience and support, which can be a great asset for a software development company.

Also read:

An alternative called Silverlight