Expression & Silverlight
By Tim Anderson
Tim Anderson finds out what the new versions of Microsoft Silverlight and Expression Blend have to offer.
HardCopy Issue: 46 | Found In: Development | Published: 01/11/2009 | Last Revision: 06/07/2010
Microsoft’s Silverlight platform is evolving at a rapid pace. First announced in late 2005 as Windows Presentation Foundation Everywhere (WPF/E), Silverlight is a cross-platform browser plug-in that enables video playback, multimedia and the development of Rich Internet Applications (RIA) that blur the boundaries between desktop and Web applications. Silverlight 1.0 came out in September 2007.
If that sounds similar to Adobe Flash, then in some ways it is. However Silverlight 2, released in October 2008, added a powerful Microsoft-specific feature by including a cut-down version of the .NET Framework which meant that Silverlight applications running in the browser can execute C# or Visual Basic code, or even dynamic languages such as Iron Python and Iron Ruby.
Sometimes this is misunderstood to mean that Silverlight requires the .NET Framework to be installed, just as Sun’s JavaFX requires Java. This is not the case: Silverlight has its own build of the .NET Framework and has no further dependencies. This is great for deployment, thanks to Silverlight’s small size and ease of installation, but does mean that developers are restricted to a subset of the full Framework. There are also security issues, with Silverlight applets sandboxed in the same way as JavaScript running in the browser.
Silverlight grows up
In March 2009, less than six months after pushing out Silverlight 2.0, Microsoft announced version 3.0 of the product, and by mid-July it was fully released. Despite the short release cycle, the changes are extensive. On the video side, there is support for the popular H.264 codec along with AAC audio, as well as improved streaming and hardware acceleration. On the application side, significant features include out-of-browser support, more powerful graphics, ClearType text, a navigation framework with deep linking, numerous additional controls, binary XML for more efficient Web services, and a new server-side framework called RIA Services.
This Silverlight application is running out-of-browser. It is still a Web application, but was started from the desktop and is running within its own window.
Out-of-browser support is significant as it enables a new class of application: a Silverlight applet that runs on the desktop without any containing Web page, which has its own Start menu entry and/or desktop shortcut, and runs on Intel Mac as well as Windows. The difference is not so great under the covers, since out-of-browser applications remain sandboxed. This makes out-of-browser Silverlight applets easy to deploy, without requiring the user to pass a security dialog, but less powerful than native desktop applications. That said, launching an application from the desktop can make a big difference to the user. Access to isolated local storage does enable offline support for applications that have been coded with this in mind.
Enabling a Silverlight applet to run outside the browser is trivial, involving just a few lines in the application manifest (an XML file used for configuration).
The big change in Silverlight 3 graphics is the introduction of a bitmap API. The WriteableBitmap class gives you programmatic pixel-by-pixel control of an image. This means any graphical effect or custom user interface can be coded, though you have to work out the mathematics yourself. The PixelShader API lets you create both static and transition effects such as blurs, ripples and swirls using Microsoft’s High Level Shading Language (HLSL). Once created you compile them, and then apply them to Silverlight elements. Although creating effects is tricky, using them is easy, and an extensive library is available for download.
There is also a 3D perspective that lets you apply 3D rotations to objects. This is not full 3D support - there is no camera, for example - but does enable some interesting effects.
The navigation framework in Silverlight 3 introduces a Frame component that can contain XAML that is defined in another file. At runtime you can call the Navigate method to change the source to a different file, similar to the way a browser handles Web pages.
Another aspect of the navigation API is that you can define URLs that link to specific content within a Silverlight application. This is called deep linking, and is important for SEO (Search Engine Optimization) if a lot of content on a Web site is locked within Silverlight.
The navigation API hooks into the browser history as well, so users get forward and back button support if the developer allows it.
Doing the business
Many business applications are database applications, and Silverlight 3 is greatly improved for this type of programming. New controls such as the DataGrid, DataPager, and DatePicker are now in the SDK. Some of these are also part of the Silverlight Toolkit, an official set of downloadable controls that is updated regularly and is an essential resource for Silverlight coders. The Toolkit also offers a DataForm and DataField with validation support. Although Silverlight 3 is not as mature as, say, Windows Forms when it comes to line of business applications, it is already usable and improving fast.
The challenge of database applications is not only the user interface but also working with Web services to deliver data and enable critical features such as authentication, authorisation, business rules and data updates. Silverlight 3 introduces a server piece called RIA Services which addresses this. When you create a Silverlight project, you can enable RIA Services by checking a box. Once done you can write code for a DomainService class on the server, and have its entities and operations automatically exposed to the Silverlight client via a proxy class.
RIA Services also extend the ASP.NET Membership framework to Silverlight clients. The Membership framework defines users and roles based on either Windows or Forms authentication. In your Silverlight application, the RiaContext class lets you check the current user’s state and roles so that the UI can be modified dynamically according to the available permissions. RIA Services are not yet done: the current release is only a technical preview. However long term this will be critical to the value of Silverlight in business. The Silverlight model, with data and business logic in the cloud, and a cross-platform client which is rich in UI but lightweight in every other respect, fits well with development trends.
Silverlight Tooling
The whole WPF and Silverlight initiative came about because Microsoft woke up to the importance of design in today’s applications and Web sites. The company therefore gave thought to the problem of designers and developers working side by side from the beginning. The core concept it came up with is XAML as the underlying language that defines the user interface, and to this end it provides two tools that work with XAML: Expression Blend for designers, and Visual Studio for developers. Both tools can open and edit the same projects, allowing designers and developers to literally work together. Expression Blend is Microsoft’s design tool for both Silverlight and WPF.
Although the concept seems a good one, in practice there are snags. One is that many designers already use Adobe’s tools, especially Photoshop, and often work on a Mac. Another issue is that passing projects back and forth between design and development departments often does not fit with real-world workflow.
Expression Blend 3 introduces two key features that greatly improve matters. The first is the ability to import Photoshop and Illustrator files while retaining layers, shapes and text elements, making it far easier to design in Photoshop and finish in Expression. The second is a new feature called SketchFlow that enables easy prototyping and collaboration. When SketchFlow was first shown at the Mix conference in Spring 2009, it was the unexpected hit of the show, thanks to its good fit with prototyping tasks.
SketchFlow has several components. Within Blend, there are special prototyping controls and styles that look deliberately rough, making users less inhibited about suggesting changes. There are also tools for laying out application flow visually. When complete, you can package a SketchFlow project into a bundle that is itself a Silverlight application. Others can then view and exercise the prototype, add verbal or graphical comments, and export their feedback for the designer to see. SketchFlow projects can also be exported to a Word document to create a more traditional application proposal.
SketchFlow is a feature in Expression Blend 3 that lets designers easily create and circulate prototype designs for discussion.
Another new Blend feature is Behaviors. These let designers add simple interactions to Blend projects without writing code, and reflect the fact that today’s designs are dynamic. Visual Studio 2008 is an excellent tool for writing Silverlight code, and has its own visual designer for WPF. Silverlight design support on the other hand is rudimentary, with just a XAML code editor and a read-only visual view that was removed in a service pack. Visual Studio 2010 is when it all comes together, with a new Silverlight visual designer that is sufficient for developers working with simple layouts.
Most-wanted
Silverlight has matured considerably in version 3, but developers are hungry for more. The most obvious lack is print support, which came top of the list of feature requests in a recent poll. There are workarounds, such as generating a PDF on the server and opening it in Adobe Reader. Another common gripe is that Silverlight has no access to devices like webcams and barcode readers. Rich text support is a third problem: Silverlight has no rich text editor or display control, though limited text formatting is available in XAML.
Developers would also like to see more access to the local system for out-of-browser applications, enabling features like notifications or opening documents directly in local applications, features which are already on offer in Adobe AIR. Databinding is another issue, since Silverlight is well behind the Windows-only WPF in this respect. Finally, Microsoft is behind Adobe Flash in mobile support, and with ‘smartphones’ growing in importance this is a severe lack. Presuming Microsoft is paying attention, some of these features may turn up in Silverlight 4.
Silverlight 3 and Expression Blend 3 are major advances, and if nothing else they show how seriously Microsoft is taking its RIA platform. Although some parts are not yet mature, progress is rapid, and for .NET developers who want to move towards a Web application model but with rich cross-platform clients, Silverlight is the obvious solution and its future seems assured.