Cincom Smalltalk Community Blogs

Windows Presentation Foundation (WPF) and Silverlight
September 06, 2007 09:07:03 EDT Microsoft has released Silverlight 1.0. There are lot example applications up. See for example this beta application showing a search UI made in Silverlight. Silverlight is often portrayed as Microsoft’s Flash-killer. Flash is important as a tool for showing rich multimedia content, but in the future, frameworks like this might be the new platform applications are based on. Silverlight’s architecture is interesting. It includes parts of Windows Presentation Foundation (WPF), but runs on more operating systems. First some words on WPF… WPF is Microsoft’s new GUI framework that replaces all of the old “Windows Forms” and Win32 API. It builds on a vector based and GPUenabled drawing framework (DirectX), and adds the ability to create richer UIs than Windows Forms does. The look and feel is also new. In my view, WPF is Microsoft most important project the last years. Everybody is discussion Windows Vista, but WPF is probably more important for application developers than Vista is. WPF also runs on Windows XP, so it is not tied to Vista. Read this and this and this to get a better understanding of WPF. Also watch this video. Even if you never plan to use WPF, knowing the technology and the concepts is useful. WPF applications can be deployed to the desktop or run in Internet Explorer (on Windows only, as far as I know). When WPF application run in Internet Explorer they run in a sandbox, so users simply point Internet Explorer at an URL and your application appears without any installation or confirmation need. All development tools are the same (Visual Studio) when making desktop and browser-based WPF applications, and you can use the same widgets for both. WPF running in Internet Explorer have some restrictions compared to a program running on the desktop. For example, opening new windows is not possible and communication (WCF) is not allowed. Apparently SOAP calls can be used instead. Making a WPF application run in the browser is easy. You create a project in Visual Studio marking it as a “WPF Browser Application”. After compilation, you publish the executable to a web server. I think one idea in Visual Studio is to allow a desktop-based

WPF application and the same browser-based application to be produced from the same codebase. I have not tried this yet, but this looks like a promising concept. Back to Silverlight… Like WPF-applications can run in a browser, so do Silverlight applications. But Silverlight applications can be deployed to more platforms (OS X and Linux) and more browsers. This does however come with a cost… Like browsers-based WPF applications lose access to some functions compared to desktop applications, Silverlight applications can build on even less infrastructure. The GUI is one (of many) missing elements in Silverlight: “ (…) it's important to note that a lot of the staple approaches you may be familiar with from building Windows Presentation Foundation (WPF) applications will not work in Silverlight, which uses only a subset of WPF's capabilities. Silverlight does not support most of the WPF component primitives, such as Buttons and TextBoxes, and it supports only one layout type: the absolute positioning layout. As a result, porting an existing WPF application to Silverlight will force a total rewrite of all the UI-related code.” (From DevX) Of course, people are building widget libraries for Silverlight, but wouldn’t it better if WPF was fully included? There could be various reasons for not including it… One could be size, but does that really matters these days? Another reason could be that Microsoft simply does not want all other operating systems to be able to run (the new wave of) Windows programs for free. For application developers this sums up to using one of these platforms (not counting web interfaces) when writing new software in Visual Studio:
• •

WPF applications running on the desktop (Vista/XP) -- all OS features enabled. WPF applications running sandboxed in Internet Explorer on Vista & XP -missing WCF and some permissions, e.g. opening new windows.

For the two solutions above, you use same tools and frameworks. Then, for the third one you enter another world:

Silverlight running sandboxed on “major browsers” on Windows, Linux and OS X -- heavily reduced WPF (missing some 3D functions, widgets gone, etc.) Depend on other 3rd party tools for this functionality.

If you develop a Rich Internet Application, it seems like choosing between WPF and Silverlight will be an important decision that will heavily shape your project.

esigning an external-facing website, then Silverlight is the better choice because potential customers can access the website from a variety of different operating systems and browsers.

The .NET collection definedFEATURES MATRIX
The Features Matrix below provides an overview of the new capabilities in Silverlight 3. Silverlight 3 is able to run Silverlight 2 and Silverlight 1.0 applications without change.

Features Cross-Browser Support for Firefox, IE, Safari Cross-Platform Support for Windows and Mac (and Linux through the Moonlight Project) 2D Vector Animation/Graphics AJAX Support HTML DOM Integration HTTP Networking Canvas Layout Support JavaScript Support Silverlight ASP.NET Controls (asp:media, asp:xaml) XAML Parser (based on WPF) Media – 720P High Definition (HD) Video Media – Audio/Video Support (VC-1, WMV, WMA, MP3) Media – Image Support (JPG, PNG) Media Markers Windows Media Server Support Support for Visual Basic.NET and C#; Common Language Runtime (CLR) based languages Support for IronPython, IronRuby, Managed JScript, and other Dynamic Language Runtime (DLR) based languages Rich Core Framework (e.g. Generics, collections)

Silverlight 1.0

Silverlight 2

Silverlight 3

Features Multi-Threading Layout controls including StackPanel and Grid Full suite of Controls (TextBox, RadioButton, Slider, Calendar, DatePicker, DataGrid, ListBox, TabControl, and others) Managed Control Framework Templating Model Visual State Manager Isolated Storage Deep Zoom Technology Media – DRM Powered by PlayReady Media - Windows Media Audio 10 Professional support Media - MediaStreamSource for managed code media file parser and protocol extensibility High quality resizing Media - Basic SSPL Support Cross Domain Network Access Easy access to server-side data via Web Services Direct access to TCP sockets Interoperability with SOAP and REST services, including support for XML, JSON, RSS and Atom data formats LINQ (including LINQ to XML, LINQ to JSON, and LINQ to Entities) Duplex communications (“push” from Server to Silverlight client) Data Binding

Silverlight 1.0

Silverlight 2

Silverlight 3

Features ADO.NET Data Services Managed HTML Bridge Managed Exception Handling .NET Framework Security Enforcement Type Safety Verification XMLReader/Writer Enhanced Keyboard Input Support File Upload Support (via WebClient API) WPF Compatibility Accessibility Localization Remote Debugging (PC and Mac) Out of Browser Network Status (Offline) Pixel Shader Effects Bitmap API Theming at runtime Enhanced Control Skinning Accessibility - System Colors Bitmap caching Perspective 3D GPU Hardware Acceleration (for video and bitmaps) Text Animation H.264 Support

Silverlight 1.0

Silverlight 2

Silverlight 3

Features Raw A/V Support File Save Dialog DockPanel, WrapPanel, Viewbox Local Fonts Element to Element Binding Local Connection Binary XML Component Caching (share resources across apps) Scene caches (to Bitmap)

Silverlight 1.0

Silverlight 2

Silverlight 3

From a .NET perspective, a collection could be defined as an object that implements one or more of the System.Collections.ICollection, System.Collections.IDictionary, and System.Collections.IList interfaces. This definition leads to my classification of the "builtin" collections found in the System.Collections namespace into three broad categories:

Ordered collections: Collections that implement only the ICollection interface are usually distinguished by the fact that insertion order controls the order in which objects may be retrieved from the collection. The System.Collections.Stack and System.Collections.Queue classes are both examples of ICollection collections. Indexed collections: IList-implementing collections are distinguished by the fact that their contents can be retrieved via a zero-based numeric index, like an array. The System.Collections.ArrayList object is one example of an indexed collection. Keyed collections: Collections implementing the IDictionary interface contain items that can be retrieved by an associated key value of some kind. The contents of IDictionary collections are also usually sorted in some fashion based on the key valu and can be retrieved in sorted order by enumeration. The System.Collections.HashTable class implements the IDictionary interface.

As you can see, the functionality of a given collection is very much controlled by the specific interface or interfaces it implements. If you don't have much exposure to objectoriented programming, that may seem awfully confusing, if not entirely pointless. You should know, however, that building an object's functionality in this manner not only gives families of similar objects similar sets of method signatures, but it also allows them to be treated as essentially the same class when necessary—a technique known as

polymorphism among OOP initiates. Guided tour of System.Collections The System.Collections namespace contains six built-in, generic collections that you can use in your applications. A few other, more specialized collections are found in System.Collections.Specialized, and you may find them useful in certain circumstances. With a few exceptions, each of these specialized collections is similar in functionality to one of the built-in collections. Let's take a look at each of the generic collections and a few of the less esoteric specialized collections. Stacks and queues The System.Collections.Stack and System.Collections.Queue classes, which both implement the ICollection interface only, hold items of type System.Object in the order they were added to the collection. Objects can be retrieved from the collection only in this order: Stacks are last-in, first-out, and queues are first-in, first-out. Typically, you'll want to consider using one of these collections when:
• • •

The order in which items are received and processed is important. You can discard an item after processing it. You don't need to access arbitrary items in the collection.

ArrayList The System.Collections.ArrayList class, which implements only IList, could best be described as a hybrid of a normal array and a collection. ArrayLists hold items in the order they were added. Items are assigned an index identifier and can be retrieved in any order via their associated index number. The ArrayList grows as new items are added to it, which makes it more flexible than a normal array. However, an ArrayList has more overhead than a traditional array and is not strongly typed, accepting anything that can be cast to System.Object (in other words, everything). SortedList System.Collections.SortedList, which implements both the IDictionary and ICollection interfaces, is your basic sorted collection, with the most similarity to VB6's Collection object. SortedLists store objects and sort them based on an associated key. They also are the only built-in .NET collection to support retrieval of objects by both index number and key. HashTable The powerful System.Collections.HashTable collection implements both IDictionary and ICollection and can be used to store multiple items of type Object, along with an associated unique string key. Items in a HashTable are sorted in an order determined by a hash code derived from their key. While each object's key value in the collection must be unique, its hash code need not be.

What's a hash code? A hash code is essentially the result of removing all redundant parts from a piece of data, and it serves as an aid to categorizing or sorting the data. When an item is added to the collection, HashTable calls the key's GetHashCode method, which all classes inherit from System.Object, to determine its hash code and place in the sort order. You can force the use of a custom hash function either by overriding the GetHashCode method of a class or by passing an object implementing the System.Collections.IHashcodeProvider interface to the HashTable constructor, in which case that object will be used to generate hash codes for all keys added to the collection. From a performance standpoint, HashTables can retrieve an arbitrary element from the collection very quickly because key searches are limited only to keys with the same hash code, which reduces the number of keys that must be checked to find a match. However, because a hash code must be generated for each object and key pair that's inserted into the collection, item insertions are somewhat expensive. Therefore, HashTables are ideal for situations where a large amount of relatively static data will be repeatedly searched for arbitrary keys. ListDictionary and HybridDictionary The ListDictionary and HybridDictionary classes are found in System.Collections.Specialized. Both organize items based on a unique key value, and both implement IDictionary and ICollection. The ListDictionary stores items internally as a linked list and is recommended for collections that won't grow much larger than 10 items. The HybridDictionary uses an internal linked list (actually a ListDictionary) for small collections and will convert that to a HashTable when the collection grows large enough (more than about 10 items, in case you haven't been paying attention) to make the linked list implementation inefficient. StringCollection and StringDictionary System.Collections.Specialized.StringCollection and System.Collections.Specialized.StringDictionary are both optimized for storing collections of strings. StringCollection implements both IList and ICollection and is essentially an ArrayList that is strongly typed to accept only strings. StringDictionary is a HashTable that has been strongly typed to accept only strings. StringCollection is ideal for smaller amounts of data that is frequently updated or added to, while StringDictionary is best suited for large amounts of data that will not be frequently added to, such as a HashTable. NameValueCollection System.Collections.Specialized.NameValueCollection is interesting in that it can contain multiple items associated with the same key value, which distinguishes it from all the other built-in collections. Aside from this, it functions similarly to a HashTable, sorting items based on a hash code derived from each item's key and thus has essentially the same advantages and disadvantage

Difference between Silverlight Version 1.0 and Silverlight Version 1.1
A lot of my friends who want to get started with Silverlight development keep asking me what's the difference between Silverlight 1.0 and Silverlight 1.1? Which version should they use? Which version supports what? The primary difference between the two versions is: you can only use JavaScript to create Silverlight applications in version 1.0, however you can use your favorite language, be it C#, VB, IronRuby or IronPython to create Silverlight applications in version 1.1. For detailed information on the features of Silverlight versions 1.0 and 1.1, click here.

FEATURES MATRIX
The Features Matrix below provides an overview of the new capabilities in Silverlight 3. Silverlight 3 is able to run Silverlight 2 and Silverlight 1.0 applications without change.

Features Cross-Browser Support for Firefox, IE, Safari Cross-Platform Support for Windows and Mac (and Linux through the Moonlight Project) 2D Vector Animation/Graphics AJAX Support HTML DOM Integration HTTP Networking Canvas Layout Support JavaScript Support Silverlight ASP.NET Controls (asp:media, asp:xaml) XAML Parser (based on WPF) Media – 720P High Definition (HD) Video Media – Audio/Video Support (VC-1, WMV, WMA, MP3)

Silverlight 1.0

Silverlight 2

Silverlight 3

Features Media – Image Support (JPG, PNG) Media Markers Windows Media Server Support Support for Visual Basic.NET and C#; Common Language Runtime (CLR) based languages Support for IronPython, IronRuby, Managed JScript, and other Dynamic Language Runtime (DLR) based languages Rich Core Framework (e.g. Generics, collections) Multi-Threading Layout controls including StackPanel and Grid Full suite of Controls (TextBox, RadioButton, Slider, Calendar, DatePicker, DataGrid, ListBox, TabControl, and others) Managed Control Framework Templating Model Visual State Manager Isolated Storage Deep Zoom Technology Media – DRM Powered by PlayReady Media - Windows Media Audio 10 Professional support Media - MediaStreamSource for managed code media file parser and protocol extensibility High quality resizing Media - Basic SSPL Support Cross Domain Network Access Easy access to server-side data via Web

Silverlight 1.0

Silverlight 2

Silverlight 3

Features Services Direct access to TCP sockets Interoperability with SOAP and REST services, including support for XML, JSON, RSS and Atom data formats LINQ (including LINQ to XML, LINQ to JSON, and LINQ to Entities) Duplex communications (“push” from Server to Silverlight client) Data Binding ADO.NET Data Services Managed HTML Bridge Managed Exception Handling .NET Framework Security Enforcement Type Safety Verification XMLReader/Writer Enhanced Keyboard Input Support File Upload Support (via WebClient API) WPF Compatibility Accessibility Localization Remote Debugging (PC and Mac) Out of Browser Network Status (Offline) Pixel Shader Effects Bitmap API

Silverlight 1.0

Silverlight 2

Silverlight 3

Features Theming at runtime Enhanced Control Skinning Accessibility - System Colors Bitmap caching Perspective 3D GPU Hardware Acceleration (for video and bitmaps) Text Animation H.264 Support Raw A/V Support File Save Dialog DockPanel, WrapPanel, Viewbox Local Fonts Element to Element Binding Local Connection Binary XML Component Caching (share resources across apps) Scene caches (to Bitmap)

Silverlight 1.0

Silverlight 2

Silverlight 3

The Silverlight Platform The Silverlight platform as a whole consists of two major parts, plus an installer and update component, as described in the following table.
Component Core Description Components and services oriented toward the UI and user interaction, including

presentation framework

user input, lightweight UI controls for use in Web applications, media playback, digital rights management, data binding, and presentation features, including vector graphics, text, animation, and images. Also includes the Extensible Application Markup Language (XAML) for specifying layout. A subset of the .NET Framework that contains components and libraries, including data integration, extensible Windows controls, networking, base class libraries, garbage collection, and the common language runtime (CLR). Some parts of the .NET Framework for Silverlight are deployed with your application. These "Silverlight Libraries" are assemblies not included in the Silverlight runtime and are instead shipped in the Silverlight SDK. When Silverlight Libraries are used in your application, they are packaged up with your application and downloaded to the browser. These include new UI controls, XLINQ, Syndication (RSS/Atom), XML serialization, and the dynamic language runtime (DLR). An installation and update control that simplifies the process of installing the application for first-time users, and subsequently provides low-impact, automatic updates.

.NET Framework for Silverlight

Installer and updater

The following illustration shows these components of the Silverlight architecture, along with related components and services. Silverlight architecture

There is a particular value in the combined set of tools, technologies, and services included in the Silverlight platform: They make it easier for developers to create rich, interactive, and networked applications. Although it is certainly possible to build such applications using today's

Web tools and technologies, developers are hindered by many technical difficulties, including incompatible platforms, disparate file formats and protocols, and various Web browsers that render pages and handle scripts differently. A rich Web application that runs perfectly on one system and browser may work very differently on another system or browser, or may fail altogether. Using today's large array of tools, protocols, and technologies, it is a massive and often cost-prohibitive effort to build an application that can simultaneously provide the following advantages:

Ability to create the same user experience across browsers and platforms, so that the application looks and performs the same everywhere.

Integration of data and services from multiple networked locations into one application using familiar .NET Framework classes and functionality.

• •

A media-rich, compelling, and accessible user interface (UI). Silverlight makes it easier for developers to build such applications, because it overcomes many of the incompatibilities of current technologies, and provides within one platform the tools to create rich, cross-platform, integrated applications.

Core Presentation Components The core presentation features of the Silverlight platform, shown in the previous section and illustration, are described in the following table.
Feature Input UI rendering Media Description Handles inputs from hardware devices such as the keyboard and mouse, drawing, or other input devices. Renders vector and bitmap graphics, animations, and text. Features playback and management of various types of audio and video files, such as .WMP and .MP3 files.

Deep Zoom Enables you to zoom in on and pan around high resolution images.

Controls Layout Data binding DRM XAML

Supports extensible controls that are customizable through styling and templating. Enables dynamic positioning of UI elements. Enables linking of data objects and UI elements. Enables digital rights management of media assets. Provides a parser for XAML markup.

Developers can interact with this presentation framework by using XAML to specify presentation details. XAML is the primary point of interaction between the .NET Framework and the presentation layer. Developers can programmatically manipulate the presentation layer using managed code. The .NET Framework for Silverlight The following table describes a partial list of the .NET Framework for Silverlight features shown in the previous illustration.
Feature Data Description Supports Language-Integrated Query (LINQ) and LINQ to XML features, which ease the process of integrating and working with data from disparate sources. Also supports the use of XML and serialization classes for handling data. A set of .NET Framework libraries that provide essential programming functions, such as string handling, regular expressions, input and output, reflection, collections, and globalization. Provides features to simplify access to remote services and data. This includes a browser object, HTTP request and response object, support for cross-domain HTTP requests, support for RSS/Atom syndication feeds, and support for JSON, POX, and SOAP services. Provides memory management, garbage collection, type safety checking, and exception handling. Provides a rich set of controls, including Button, Calendar, CheckBox, DataGrid, DatePicker, HyperlinkButton, ListBox, RadioButton, and ScrollViewer. Supports the dynamic compilation and execution of scripting languages such as JavaScript and IronPython to program Silverlight-based applications. Includes a pluggable model for adding support for other languages for use with Silverlight.

Base class library

Window Communication Foundation (WCF) CLR (common language runtime) WPF (Windows Presentation Foundation) controls DLR (dynamic language runtime)

The .NET Framework for Silverlight is a subset of the full .NET Framework. It provides the essentials of robust, object-oriented

application development for application types (such as Internet applications) for which this support has not traditionally been available. Developers can interact with the .NET Framework for Silverlight layer by writing managed code using C# and Visual Basic. .NET Framework developers can also access the presentation layer by authoring in Visual Studio 2008 or Microsoft Expression Blend. Additional Silverlight Programming Features Silverlight provides several additional features that help developers create rich and interactive applications, including those described in the following table.
Feature Isolated storage Asynchronous programming File management HTML–managed code interaction Description Provides safe access from the Silverlight client to the local computer's file system. Enables local storage and caching of data isolated to a particular user. A background worker thread carries out programming tasks while the application is freed up for user interaction. Provides a safe File Open dialog box, to ease the process of creating safe file uploads. Enables .NET Framework programmers to directly manipulate UI elements in the HTML DOM of a Web page. Web developers can also use JavaScript to call directly into managed code and access scriptable objects, properties, events, and methods. Provides support for serialization of CLR types to JSON and XML. Provides the Application class and build tools to create .xap packages. The .xap package contains the application and entry point for the Silverlight plug-in control to run. XmlReader and XmlWriter classes simplify working with XML data from Web services. The XLinq feature enables developers to query XML data directly within .NET Framework programming languages.

Serialization Packaging

XML libraries

Related Technologies and Tools The following Microsoft applications include special features for Silverlight development:

Microsoft Expression Blend. This tool can be used to create and modify the presentation layer of an application by manipulating the XAML canvas and controls, working with graphics, and programming the presentation layer with a dynamic language such as JavaScript.

Visual Studio 2008. Visual Studio provides productivity tools for developing applications using managed code. All the existing features of Visual Studio are available for Silverlight. In addition, this version of Visual Studio includes Silverlight-specific features, including IntelliSense, debugging, and Silverlight project templates that create and link all required files.

Because Silverlight-based applications are executed in a run-time environment on the client machine, no particular application is required to be installed on the server. However, developers may find that their ability to create rich applications that integrate services and data from multiple sources on the server is enhanced by integrating the following types of services and server-side applications into their Silverlight-based applications:

ASP.NET AJAX. This includes a set of controls, services, and libraries for creating rich and interactive Web-based applications. Microsoft Windows Communication Foundation (WCF) services. Internet servers, including Microsoft Internet Information Services (IIS), and the Apache Web server. Internet-based applications and services, including Microsoft ASP.NET, PHP, Windows Streaming Media services, Windows Live services, and other open Web services.

• •