Professional Documents
Culture Documents
Silverlight Overview
Microsoft Silverlight is a cross-browser, cross-platform implementation of the .NET Framework
for building and delivering the next generation of media experiences and rich interactive
applications (RIA) for the Web. Silverlight unifies the capabilities of the server, the Web, and the
desktop, of managed code and dynamic languages, of declarative and traditional programming,
and the power of Windows Presentation Foundation (WPF).
To run a Silverlight-based application, users require a small plug-in in their browser. The
plug-in is free. If users do not already have the plug-in, they are automatically prompted
to install it. The download and installation take seconds and require no interaction from
the user except permission to install.
2. Silverlight Architecture
Feature Description
Handles inputs from hardware devices such as the keyboard and mouse,
Input
drawing, or other input devices.
UI
Renders vector and bitmap graphics, animations, and text.
rendering
Features playback and management of various types of audio and video
Media
files, such as .WMP and .MP3 files.
Deep Zoom Enables you to zoom in on and pan around high resolution images.
Feature Description
Supports Language-Integrated Query (LINQ) and LINQ to XML features,
which ease the process of integrating and working with data from
Data
disparate sources. Also supports the use of XML and serialization classes
for handling data.
A set of .NET Framework libraries that provide essential programming
Base class library functions, such as string handling, regular expressions, input and output,
reflection, collections, and globalization.
Window Provides features to simplify access to remote services and data. This
Communication includes a browser object, HTTP request and response object, support for
Foundation cross-domain HTTP requests, support for RSS/Atom syndication feeds,
(WCF) and support for JSON, POX, and SOAP services.
CLR (common Provides memory management, garbage collection, type safety checking,
language runtime) and exception handling.
WPF (Windows
Provides a rich set of controls, including Button, Calendar, CheckBox,
Presentation
DataGrid, DatePicker, HyperlinkButton, ListBox, RadioButton, and
Foundation)
ScrollViewer.
controls
Supports the dynamic compilation and execution of scripting languages
DLR (dynamic such as JavaScript and IronPython to program Silverlight-based
language runtime) applications. Includes a pluggable model for adding support for other
languages for use with Silverlight.
Silverlight and WPF share many of the same features and capabilities, but they are built on top of
different run-time stacks, as illustrated in the figure below. WPF leverages the full .NET Framework
and executes on the common language runtime (CLR). Silverlight is based on a subset of XAML
and the full .NET Framework, and it executes on a browser-hosted version of the CLR.
This section describes some of the major differences the patterns & practices team encountered
during the development of the Composite Application Guidance for WPF and Silverlight. These
differences relate to Silverlight 2.0 and WPF 3.5, the current versions at the time of this writing.
3.2.1. Resources
Resources are simple collections of key-value pairs that can store almost any element
(strings, brushes, styles, data sources, and many others). Resources can be associated with
almost any element class that exposes a Resources property of type
ResourceDictionary. The following are the main differences between Silverlight and WPF
concerning resources:
3.2.3. Triggers
Triggers allow designers to define the visual behavior of a control by declaratively specifying how
its properties change in response to events or property changes, such as highlighting a button
when it is clicked. Typically, triggers are fired when a property of a control changes and results in
one or more other properties of that control also changing. Triggers are defined inside a style and
can be applied to any object of the specified target type.
In Silverlight, there is no support for the ElementName property in the binding syntax, so
the property of a control cannot be bound to a property in another control. In addition,
Silverlight does not support the RelativeSource property, which is useful when the
binding is specified in a ControlTemplate or a Style.
In Silverlight, there is no OneWayToSource data flow mode.
In Silverlight, there is no UpdateSourceTrigger property. All updates to the source in the
two-way binding mode occur immediately, except in the case of TextBox, in which case
changes are propagated to the source when the focus is lost.
In Silverlight, you cannot bind directly to XML data. A possible workaround for this is to
convert the XML to CLR objects, and then bind to the CLR object.
In Silverlight, there is no XMLDataProvider class.
3.2.5. Commanding
The following are the differences between Silverlight and WPF regarding commanding:
Routed commands are not available in Silverlight. However, the ICommand interface is
available in Silverlight, allowing developers to create their own custom commands. The
Composite Application Library provides the DelegateCommand and
CompositeCommand classes to simplify command implementation.
In WPF, controls can be hooked up to commands through their Command property. By
doing this, developers can declaratively associate controls and commands. This also
means a control can interact with a command so that it can invoke the command and
have its enabled status automatically updated. Silverlight controls do not currently
support the Command property. To help work around this issue, the Composite
Application Library provides an attached property-based extensibility mechanism that
allows commands and controls to be declaratively associated with each other.
There is no input gesture or input binding support in Silverlight.
3.2.6. Miscellaneous
The following are some miscellaneous differences between Silverlight and WPF:
In Silverlight, the UIElement class has an internal constructor; therefore, you cannot
create a control inheriting from it.
In Silverlight, there is no x:type markup extension support or support for custom markup
extensions.
In Silverlight, items added to a TabControl control are not automatically wrapped inside
a TabItem type, as is the case with WPF.
4. Application Structure
One AppManifest.xaml file, which identifies the packaged assemblies and the application
entry point.
One application assembly, which includes your application class.
Zero or more library assemblies.
Zero or more loose resource files, such as images or video files.
The AppManifest.xaml file is typically generated by the build process, and uses XAML markup
to declare a Deployment object for your application.
In the AppManifest.xaml file, the Deployment element includes the following attributes:
The following diagram summarizes the application package structure and deployment options for
your application files.
The Silverlight plug-in life cycle begins when a user navigates to a Web page that hosts the
Silverlight plug-in. If the user has installed Silverlight, the Web browser activates the plug-in and
begins downloading your application package.
The plug-in loads the Silverlight core services followed by the Silverlight common language
runtime (CLR), which creates an AppDomain for your application. When your application
package download is complete, the CLR instantiates your Application class and raises its Startup
event.
You can add code to your application class constructor. However, you typically use a Startup
event handler for most application initialization tasks, such as displaying a user interface page.
You cannot use this splash screen model effectively if your main source content is using the
JavaScript API also. This is because the splash screen model relies on the notification that
comes from a loaded managed AppDomain as the signal to stop displaying
SplashScreenSource and start displaying Source. You could simulate the same apparent
transitional behavior by the following sequence:
<Canvas
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="parentCanvas"
Width="850"
Height="600"
Background="OldLace"
>
<Canvas Canvas.Top="228.834" Canvas.Left="246.329" Width="357"
Height="31.379">
<Rectangle Width="27.545" Height="1" x:Name="uxProgress"
Canvas.Top="29.545" Canvas.Left="1.4">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="uxProgressBar" ScaleX="1" ScaleY="0"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="270"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFFFFFFF" Offset="1"/>
<GradientStop Color="#FFFFFFFF" Offset="0"/>
<GradientStop Color="#FF2975D0" Offset="0.28"/>
6. The second params element is referencing a JavaScript event handler, which you must
now define. Right-click SplashScreenSource.Web in the Solution Explorer. Find the file
SplashScreen.js in the solution's file list (this file was added when you added
SplashScreen.xaml in a previous step. Open SplashScreen.js for editing.
7. Delete all pre-existing content of SplashScreen.js. Paste in the following
onSourceDownloadProgressChanged function, which will update the progress bar in
SplashScreen.xaml.
9. Build your project and make sure that it compiles. The start action at this point will now
load SplashScreenSourceTestPage.html and first load your splash screen, and then the
source.
10. Clear your browser cache (otherwise, the assembly might still be cached as content by the
browser, and you will not experience the load time). Run the application again.
6. Out-of-Browser Support
You can configure Silverlight-based applications so that users can install them from their host
Web pages and run them outside the browser.
1. In Solution Explorer, select the Silverlight project for which you want to enable out-of-
browser support.
2. On the Project menu, select project name Properties.
3. On the Silverlight tab, select Enable running application out of the browser.
4. Specify values for the indicated fields and then click OK. All fields are optional except
for the following:
o Window Title
o Shortcut name
o Download description
7. Controls
8. Animations
Animation is an illusion that is created by quickly cycling through a series of images, each
slightly different from the last. The brain perceives the group of images as a single changing
scene. In film, this illusion is created by using cameras that record many photographs, or frames,
each second. When the frames are played back by a projector, the audience sees a moving
picture. In Silverlight, you animate objects by applying animation to their individual properties.
For example, to make a UIElement grow, you animate its Width and Height properties. To make
a UIElement fade from view, you animate its Opacity property. Silverlight contains many objects
that have properties that can be animated.
Note: In Silverlight, you can perform simple animations only on properties whose values are of
type Double, Color, or Point. In addition, you can animate properties of other types by using
ObjectAnimationUsingKeyFrames, but this is done using discrete interpolation (jumping from
one value to another), which is not what most people consider to be true animation.
The following table shows several common animation types and some properties that they are
used with.
Corresponding
Property basic Corresponding key-frame
Usage example
type (From/To/By) animation
animation
Animate the Color
of a
Color ColorAnimation ColorAnimationUsingKeyFrames
SolidColorBrush or
a GradientStop.
Animate the Width
of a Rectangle or
Double DoubleAnimation DoubleAnimationUsingKeyFrames the Height of an
Ellipse (or any
FrameworkElement)
Animate the Center
Point PointAnimation PointAnimationUsingKeyFrames position of an
EllipseGeometry.
Animate the Fill
property from one
Object None ObjectAnimationUsingKeyFrames
GradientBrush to
another.