Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It was 2006 when Silverlight made its debut with the confusing acronym WPF/E, for Windows Presentation Foundation/Everywhere. Like many other developers at the time, my first reaction was to dismiss the technology as yet another plug-in. Silverlight struggled in its early days to prove its identity as something more powerful than just another media player. Through an extremely rapid release cycle, Version 3.0 became available in 2009 and .NET developers began to take notice.
At the time I was working on an extremely large web-based enterprise application that provided a desktop-like experience using HTML and JavaScript. Our developers had to become experts not only in multiple languages—switching between XML, JavaScript, C#, and CSS—but also with the nuances of the multiple browser implementations that existed at the time. We were spending more time testing for cross-browser compatibility and hacking JavaScript and CSS than we were building core business functionality.
I decided to take Silverlight for a spin and started with a simple proof of concept. I found that because Silverlight used a smaller version of the core .NET Framework and could be written in my language of choice (C#), it was very easy to learn. I was extremely impressed with the Xaml layout engine and was able to produce a prototype quickly to show our CEO. He gave me the green light to use Silverlight in our project and we started right away.
It was soon apparent to the team that Silverlight was an easier way to build web-based applications. We were able to provide an amazing, rich user experience with complex features in a very short span of time and were able to provide a consistent application across multiple browsers and platforms. I estimated that our team was able to produce software about four times faster using Silverlight than traditional web-based technologies.
Since then I’ve used Silverlight to build enterprise applications for a variety of customers across multiple verticals. From a backend server health monitoring system to online cable grid listings, a SharePoint-based risk management system to a large and complex social media monitoring application, Silverlight has made writing usable and scalable software an amazing and rewarding experience.
I’ve spent the past decade focused on highly scalable web-based enterprise applications, with the last several years working almost exclusively with Silverlight. This experience has helped me design, code, test, debug, and implement Line of Business (LOB) solutions for dozens of customers using Silverlight. I’ve done my best to take those various experiences and use them to provide you with powerful and reusable solutions in this book.
The purpose of this book is to explain how to write Silverlight applications that target enterprises and commercial customers as opposed to end users and consumers. This is the heart of what LOB is about. I intend to focus on advanced features of Silverlight that directly relate to the specific business problems that the framework is capable of solving in that context. I will concentrate on the areas and themes that have come up time and time again from my own experience.
This book is not an introduction to Silverlight. I’m assuming you either have prior Silverlight experience or have experience building LOB applications using other client technologies such as Windows Presentation Foundation or ASP.NET. I’m also assuming you are at least familiar with the concept of design patterns and the notion of decoupled code. Both of these ideas have been core to the success of the applications I’ve helped build and will be used as the foundations for the concepts presented in this book.
Whether you’re a Silverlight LOB developer looking to improve an existing application, or an experienced client technologies developer who is transitioning to Silverlight for the first time, this book will give you the guidance and proven patterns and practices you’ll need to build scalable, maintainable, and highly professional applications that run equally well on multiple platforms and browsers.
This version of the book specifically addresses Silverlight 5 using Visual Studio 2010 SP1. Silverlight runs perfectly well as a standalone client technology with no dependencies on a specific backend. It can be hosted from any type of web server, including a Unix-based Apache server. Examples in this book that involve the server are assumed to be running .NET Framework 4.0, where applicable. This book does not address the Windows Phone version of Silverlight, although many of the concepts are shared between the different versions of the runtime.
The aim of this book is to enable you to write Silverlight applications that target the enterprise. Each chapter is designed to help you discover what features are available in that area of the framework and how they are applied in a LOB setting. Code examples are provided that demonstrate the features and best practices for programming them using C#. Although different chapters may relate to various parts of a comprehensive project, the individual code samples are designed to stand on their own.
Each chapter is similarly structured. The chapters begin with an introduction to a topic and an inventory of the capabilities that topic provides. This is followed by relevant case studies from existing projects and includes code samples to demonstrate its application. The code samples are explained in detail and the topic is summarized to highlight the specific information that is most important for you to consider.
I suggest you start by reading the book from start to finish, regardless of your existing situation. Inexperienced Silverlight developers will find that their understanding grows as they read each chapter and concepts are introduced, reinforced, and tied together. Experienced Silverlight developers will gain insights into areas they might not have considered or had to deal with in the past, or simply didn’t factor into their software lifecycles. After you’ve read the book in its entirety, you will then be able to keep it as a reference guide and refer to specific chapters any time you require clarification about a particular topic.
My first computer program was written in BASIC on a TI-99/4A. From there I programmed assembly language for the Commodore 64, learned C and C++ on Unix-based systems, and later wrote supply chain management software on the midrange AS/400 computer (now known as iSeries). For the past 15 years, my primary focus has been developing scalable, highly concurrent web-based enterprise applications.
I started my work with Silverlight right before the 3.0 release. At the time, I led a team of 12 developers working on an ASP.NET mobile device management platform that relied heavily on AJAX to provide a desktop-like user experience. When it was evident that the team was spending more time learning various web technologies, such as CSS and JavaScript, and testing the application on multiple browsers and platforms than focusing on the core business value, I began researching alternative solutions and determined that Silverlight was the key our team was looking for.
Since that transition I have worked almost exclusively on Silverlight applications in the enterprise. In addition to the mobile device management software, I helped build the health monitoring system for the backend data centers that provided video streams (live and on demand) during the 2010 Vancouver Winter Olympics. I worked on a major social media analytics project that used Silverlight to present data that was mined from social networks and analyzed to provide brand sentiment. I worked with a team that built a slate-based sales interface for field agents to close sales and integrate with their point of sale system. I was on the team that produced the Silverlight version of a major e-book reading platform designed for accessibility and customized to provide interactive experiences and audio for children.
All of this work has been with the company Wintellect, founded by well-known .NET luminaries Jeffrey Richter, Jeff Prosise, and John Robbins. All three have produced countless books about the Microsoft stack, .NET Framework, and Core Language Runtime (CLR). They have trained thousands of Microsoft employees (some teams at Microsoft are required to take their courses as a prerequisite to working on their projects) and contributed to the runtime itself by writing and designing portions of the framework. The company has provided me with unique access to industry leaders and architects and their best practices and solutions for creating successful enterprise applications.
I am a certified Microsoft Silverlight developer (MCTS) and was recognized as a Microsoft Most Valuable Professional (MVP) for Silverlight in July of 2010. This was due mostly to my efforts to blog, tweet, and speak about Silverlight at various user group meetings and conferences around the country. It is this depth of experience working with Silverlight, understanding how to build server and web-based software, and migrating existing applications to Silverlight that has provided me with valuable insights into how Silverlight works within the enterprise.
Silverlight is a unique platform that has transformed over the years. Originally intended to be a vehicle to provide Xaml technologies everywhere—from Windows to OS X, Linux, and even smartphones—it has matured to become a choice platform for writing LOB applications. Microsoft summarizes Silverlight on their website with this statement:
Silverlight is a powerful development platform for creating engaging, interactive user experiences for Web, desktop, and mobile applications when online or offline. (Source: http://www.silverlight.net)
That simple statement covers a lot of ground. Silverlight is a development platform that should be familiar to most shops that already produce .NET code, regardless of whether that code is written in C#, Visual Basic, IronPython, or any other language that can sit on top of the Common Language Runtime (CLR). The layout and rendering engine, along with animations, provide the engaging and interactive experience, whereas the reach of the platform allows for the web, desktop, and mobile targets (although right now the mobile is mostly limited to Windows Phone 7).
An important aspect of Silverlight that sets it apart from other web plugins is the ability to run offline, or with an Out of Browser (OOB) experience, even when the user is disconnected from the Internet. This experience is consistent between Windows and OS X (Macintosh) platforms when a specific subset of features is used. The ability to easily deliver this experience over the Web is why many customers have chosen to adopt Silverlight.
If you asked me to summarize Silverlight in a single statement, it would be this:
Silverlight is a cross-browser, cross-platform, Xaml-based runtime that allows developers to leverage the power of the Visual Studio and Expression Blend tools and a choice of .NET languages to provide rich, interactive experiences that integrate easily with existing data and services.
This statement captures the essence of what I believe Silverlight offers. It is familiar to C# and VB.NET developers because it uses familiar tools and is also accessible to those who prefer F#, IronPython, and other languages. Although Silverlight can be developed using completely free development tools, the addition of the licensed Blend product provides a design experience that can be used to create incredible user interfaces.
Another major benefit of Silverlight as a web-based tool is the ability to integrate directly with existing web services and objects. It enables you to share data and business logic between type definitions that exist on both the client and the server. Silverlight readily consumes WCF-based services as well as REST endpoints and can serialize and deserialize data in binary, XML, ATOM, RSS, and JSON formats. The ability to seamlessly integrate with existing services, data structures, and even class behaviors makes it ideal for LOB applications.
Silverlight was first released in 2007. The first version was Xaml based and exposed the programming interface through an API that relied on JavaScript in the browser. The layout engine used HTML controls and DOM interoperability with the Silverlight runtime to function. Silverlight also provided media features such as video and audio playback. This led many developers to believe it was a direct challenge to Flash and designed as “another movie player plug-in.”
The second version, initially 1.1 and renamed to 2.0, was released just a year later in 2008. This version really opened the door for serious developers because it provided a full runtime in the form of a stripped-down version of .NET Framework 3.0. This allowed programs for Silverlight to be compiled in any language supported by .NET. The version also provided a lightweight Base Class Library (BCL) that included canned controls, network APIs, and even access to Language Integrated Query, or LINQ.
Another well-known feature added at this time came from the project code-named Seadragon that was released as DeepZoom. The technology provides a way to take extremely large images (or collections of images) and scale them to allow the user to pan and zoom without having to wait for the entire image to download. It pixelates the zoomed image and slowly increases the resolution as more information is available because the image is turned into slices and tiles of varying resolutions. Many companies used this feature to provide collages of images that could be easily browsed but then zoomed to full resolution. You can view an example of DeepZoom at http://www.wintellect.com/silverlight/deepzoom/.
In November of 2008, the Silverlight Toolkit was originally released. The toolkit is designed to provide the developer community with new components and functionality for product development. It is released out of band with the runtime and includes features such as drag-and-drop behaviors, enhanced validation, and special input controls. Some of the toolkit controls, such as the popular Viewbox for automatically sizing content, were eventually migrated into the core runtime.
Silverlight 3.0 was released during the summer in 2009. It added quite a few controls to the toolbox that developers could use to build their applications, including the popular DataGrid, which is capable of automatically generating columns and rows from a data source. It provided a rich navigation framework that allows for deep-linking into the application using URLs. The media support was extended significantly.
The most significant features, however, were the catalyst for heavy adoption of Silverlight in the enterprise. The ability to provide Silverlight as an OOB application was extremely significant because it allowed an offline experience for the first time. Users could now use the application even when disconnected from the Internet. This was unique because it enabled companies to provide an application that could run disconnected, was delivered easily over the Internet, yet would run on Mac OS X as well as Windows-based machines.
In addition, a local communications API was provided to allow Silverlight applications running on the same machine to message each other. An update mechanism was introduced that allows applications to check the server from which they were installed for updates and then to update automatically when one is available. For the first time, Silverlight could provide a full application experience that could be delivered and managed from a central location with an easy installation process over the Web.
With heavier adoption in the enterprise, Silverlight users began to complain about LOB features that were missing. These included the following:
Integration of a web camera and microphone for video and audio capture
Printing support
Advanced features users of the Windows Presentation Foundation (WPF) frequently utilized
This all changed with the release of Version 4.0 in 2010, which closed a critical gap for LOB applications by providing raster-based printing support directly from the Silverlight application. The user interface improved dramatically with the ability to send toasts or notifications that could be displayed by the host operating system (whether Windows, OS X, or others). Applications could take advantage of online content by hosting web controls capable of rendering HTML. Silverlight was extended to provide access to COM components on Windows machines. The Managed Extensibility Framework (MEF) was integrated with the runtime to provide discovery, lifetime management, extensibility, and metadata services. This release represented huge strides forward.
While Silverlight continued to gain momentum in the enterprise, it also encountered its first major hurdles between 2009 and 2010. Silverlight was originally thought of as a development platform that would eventually run everywhere, but the iPhone presented an obstacle too steep to overcome. Apple simply would not allow the Silverlight runtime to exist on their phone. At the same time, the iPad was released and became a literal overnight success. Using the same operating system as the phones, it, too, would not allow the Silverlight plug-in. This presented a tangible barrier and caused executives to begin to question what technology made more sense and had farther reach. Many heads turned to the rapidly emerging HTML5 specification as the holy grail of write once, run anywhere.
The result of this was a shift in focus from the idea that Silverlight would run anywhere to a revised notion that it was ideal for rich desktop-based applications (Windows and OS X) but not something that would end up on all smartphones. One smartphone was released that embraced Silverlight out of the box: the Windows Phone 7 series. Using an enhanced 3.0 version of Silverlight with extensions specific to the phone, it introduced a whole new wave of developers to the platform while existing Silverlight developers suddenly found themselves with unprecedented access to the mobile market. The current 7.1 version of the SDK supports an enhanced Silverlight 4.0 runtime on the Windows Phone 7.5 OS that is code-named Mango.
The general development community also reacted strongly when news of the Windows 8 operating system included demonstrations of a programming experience based on HTML5 and JavaScript. None of the announcements spoke to Silverlight or WPF. This caused concern over whether support for the two popular Xaml-based technologies would even exist in the next version. Where would Silverlight fit into this scenario?
Fortunately, Version 5.0 was announced in late 2010 and the beta released in May of 2011. The release of the version at the end of 2011 demonstrates Microsoft’s commitment to Silverlight as a platform, and the features show how it continues to power LOB experiences. This significant release managed to pack some of the most important features to date, including the following:
Various text enhancements allowing for more control over text layout and flow, character spacing, pixel-snapping, and ClearType technology
Performance enhancements ranging from an improved networking stack to the introduction of a composition thread that allows animations to run in the background without blocking (or being blocked by) the primary UI thread
Click counting and text type-ahead for improved user interaction and use of mouse, touch, and the keyboard
Vector (PostScript) based printing for improved fidelity and improved per-formance with printing
Enhanced data-binding that has more parity with WPF and enables data-binding debugging
Custom markup extensions to provide more control over Xaml
Improved trust scenarios, expanded access to the file system, and child windows for OOB applications
The introduction of Platform Invoke, or p/Invoke (a Windows-specific feature), to access unmanaged code directly from Silverlight applications
A powerful XNA-based 3D engine that renders vertices with texture-mapped surfaces, shading, lighting, backface culling, and bump maps as well as provides dynamic camera angles
These features are likely to drive increased Silverlight adoption by removing previous barriers to entry and providing a new set of tools for LOB developers to quickly and efficiently build enterprise applications.