UPDATE (March 2010): Silverlight 4 RC made available! Go read my updated post on what has changed after you read below about the core features.
That’s right, we’ve released an early beta of the next version of Silverlight. It’s really amazing to think what the team is accomplishing at the pace they are accomplishing it! Silverlight 3 released just over 3 months ago and here we are with yet another release full of features that our community has been asking for.
This beta release is a developer release. This means that this is a preview mostly for developers to understand the new features and continue to get feedback. No “end-user” runtime is available for this release, nor is a “go-live” license for customers wishing to put their applications into production. If you have questions on this, feel free to leave a comment here.
Enough blabbing, here’s the goods. WARNING: Long post ahead…but filled with information.
Download Silverlight 4 and tools
To be successful in your evaluation of Silverlight 4 you are going to need some tools. Here’s the link dump of everything:
- Visual Studio 2010 Beta 2 or Visual Web Developer Express 2010 Beta 2 (pick one)
- Silverlight Tools for Visual Studio 2010
- Expression Blend for .NET 4 Preview – for authoring Silverlight 4 and WPF 4 applications
- WCF RIA Services (formerly .NET RIA Services) (NOTE: This is actually included in the SL Tools for Silverlight 4)
- Silverlight 4 SDK CHM (offline documentation) – optionally online here as well
- Updated Silverlight Toolkit for Silverlight 4
- Developer runtimes: Windows and Mac platforms
- Silverlight 4 SDK only – not needed if you install the tools above
- Silverlight Media Framework – a new, Open Source media player framework for you to use.
These are the full set of tools to help you evaluate Silverlight 4. At a bare minimum for a developer you’ll need/want Visual Studio 2010 and the Silverlight Tools for VS.
NOTE: When you install the Silverlight Tools for VS, you get the Windows developer runtime, the Silverlight 4 SDK and the Visual Studio tools/templates. It is NOT necessary to install the SDK and developer runtimes again if you are using the tools installer. The developer runtimes are provided for you to put on other developer test machines to help test your applications. Additionally, RIA Services is also included in the Silverlight Tools for Visual Studio 2010. If you have a version of RIA Services already installed, you will need to uninstall it.
Go ahead and get the tools starting to download. In the meantime, here’s some other helpful information for you.
Silverlight 4 Resources
There are a few places for you to go to learn some things:
- this blog – hey, you are here, you might as well subscribe as well as follow me on Twitter.
- Jesse Liberty, John Papa and Adam Kinney blogs, my partners in Silverlight
- Silverlight 4 beta and WCF RIA Services forums.
- View initial Silverlight 4 learning videos with sample code in C# and Visual Basic.
- Walk through some hands-on labs.
You should bookmark and subscribe to the above sites for constant updated Silverlight information.
What’s new in Silverlight 4 – feature review
Okay, now on to the details. Sit back, switch this post to your largest monitor, and grab a drink. This is a long post intentionally to provide you with details to the framework. In each area I’ll be sure to point out if there are existing resources (labs, videos, etc.) for that specific feature and be as concise as I can as to be “to the point” about what it provides, what are the requirements and some sample code, where appropriate. Here we go with the feature dump…
With Visual Studio 2010, we finally have our designer surface back for Silverlight! Yes, you have an editable design surface for Silverlight…and actually this isn’t just limited to Silverlight 4…it is available for Silverlight 3. What is great about the Silverlight tools in VS2010 is that the databinding support is pretty rich in the designer surface as well.
Additionally, for WCF RIA Services, we have improved designer/editor support for using DomainSource classes as a Data Source in Visual Studio. Be sure to grab VS2010 for all your development needs. VS2010 allows for multi-targeting of Silverlight 3 and 4 applications.
One of the top-most requested features in Silverlight has been to enable some printing support from the Silverlight application client-side versus always having the developer do things server-side. In Silverlight 4 we’re providing a printing API that we believe to be extensible for the developer and provide you with a simple printing of a visual tree, or a highly extensible model to enable you to create a virtual visual tree to print for the end user directly from Silverlight.
As you can see above, you can wire up pre- and post-print events for any type of preparation and clean-up code. The PrintPage is the important area here where the developer would pass a UIElement to print. This could be something that already exists in the visual tree, or something that is created virtually in-memory and not even added to the visual tree.
Video and Sample Code: Printing API Basics
Do you have an application that has a need for a context-style menu (aka ‘right click’ menus)? Well, in addition to the MouseLeftButtonUp/Down events, we now enable the MouseRightButtonUp/Down events for you to attach to and handle. This enables the developer to take control over what you’d like to do when those events occur. This can be from handling simple commands for gaming (i.e., a right click is a different interaction in the game than the left click) or as well for providing context-style menus for additional functionality within the application.
The sample above shows a snippet from implementing a context menu within the application. The result of the above code looks like this:
As you can see, the event handling is simple and the flexibility exists for you, the developer, to choose what you want to happen functionally and visually when the right-click events occur.
Video and Sample Code: Right-click Mouse Events
Need access to your user’s attached (or integrated) web camera and/or microphone? You got it. With a few simple lines of code you can request permission to your users to leverage their capture devices and then capture both the audio and video.
Sample code for requesting permission:
Sample code for capturing the video:
We also provide a very simple API for enabling “snapshot” images from the webcam:
I am interested to see how these webcam/microphone features are implemented in the wild by developers!
Video and Sample Code: Webcam and Microphone Support
In previous versions of Silverlight, you had to rely on some helper classes from either DeepZoom or other sample sites to implement handling the mouse’s scroll wheel functionality on things like ListBox, etc. We’re now providing APIs for you to handle MouseWheel events. You can attach this event handler to other items as well (not just ListBox).
So as you can see, you can easily wire-up the event handler for the MouseWheel event on a particular element and respond accordingly.
Video and Sample Code: Handling MouseWheel Events
One of the requested features has been to provide an editable text control that enabled rich text editing using common rich text changes like bold, italics, different sizes, etc. Using the RichTextArea, you can now enable these types of editing areas in your application.
Here’s an example of implementing the RichTextArea control:
Video and Sample Code: RichTextArea Control
To help support development patterns like the popular Model-View-ViewModel pattern, support for commanding infrastructures is now provided on ButtonBase and Hyperlink. These exposed properties, Command and CommandParameter enable binding from a View to a ViewModel approach without the need for click event handlers in code behind files. This helps aide the pattern of separation of concerns for the UI and code layers.
In this example above, the XAML binds the Button to an event, FindMatchingProducts, from the DataContext (the “ViewModelContext” resource) as well as providing the parameter, CostThresholdFilter, from another UIElement on the page. For those implementing solutions using the MVVM pattern (or other similar patterns), this added support for ICommand is a welcome addition! Get those MVVM framework revisions working :-).
Prior to now, having a reliable method for providing contents that can be temporarily held in the machine’s “clipboard” memory area involved an IE-only solution or introducing other platforms into your Silverlight application.
With the addition of the Clipboard API, you can now have a cross-platform mechanism in Silverlight to provide this facility for you.
This sample above shows setting some simple text to the Clipboard which could then be pasted to the Silverlight application, or to other applications the user is using as this is now in the machine’s clipboard memory.
Video and Sample Code: Accessing the Global Clipboard Programmatically
When you are working in the web world, you likely are dealing with HTML content in some area. Especially if you are creating content-managed systems, sometimes that content is stored as HTML. Enabling hosting HTML content in Silverlight is now possible by providing a simple WebBrowser control that will enable you to provide string-based HTML contents or navigate to a fully interactive URL.
Sample Code (XAML):
Sample Code (C#):
As an example, here’s a Silverlight application hosting an embedded YouTube Flash video:
Hopefully this will be helpful in developing your Silverlight applications. Additionally, you can also use the HtmlBrush to fill elements using HTML content.
Video and Sample Code: Hosting HTML Content in Silverlight
One thing users have been asking for is to enable Silverlight out-of-browser (OOB) applications to have more privileges. You can now alter the OOB manifest to request more elevated permissions for your application. Using Visual Studio you can look at the project properties and enable the checkbox to add this request:
The result is that the OOB install dialog now looks a little different and warns the user of these elevated privileges:
See the next sections for things that you can do in OOB mode now while in a trusted application (aka elevated mode). It is important to note that this trusted application request still does not involve installing any additional runtime for the user…it is a part of the Silverlight 4 runtime – no additional download/framework would be required.
In order to read/write data to the user’s machine, you normally have to do it through a mechanism like OpenFileDialog (read) and SaveFileDialog (write). In Silverlight 4 you can now have direct local file access to the users’ "My” folders in their profile. These are things like MyDocuments, MyVideos, MyMusic, etc. On OSX platform these map to the same user-level profile folders like /users/timheuer/Videos.
You use the Environment namespace to get the path locations for the operation you are wishing to do.
This feature requires a trusted application (elevated permissions).
Video and Sample Code: Local File Access
Have you had the need to interoperate with device peripherals that only expose a COM interface? What about having your Silverlight application talk with Office applications? Using the ComAutomationFactory API, you can now have your Silverlight application instantiate and interact with COM applications on the Windows client.
Sample Code (interacting with Excel):
This feature requires a trusted application (elevated permissions). Notice that this is done via the dynamic keyword in C# 4.0. One thing to also note that in the tooling you will not get IntelliSense support for your COM created objects. Keep that documentation for that API handy!
Video and Sample Code: COM Object Access in Trusted Applications
Ever want your application to provide a notification mechanism to the user? This is often referred to as “toast” where a subtle notification temporarily displays in the user’s screen providing some information provided by the application. Perhaps one of the more common uses of this is in mail applications, like Outlook, where new mail notifications pop-up message notification windows near the system tray in Windows.
By using the NotificationWindow in Silverlight, you can provide a simple or customized notification mechanism for your application.
Here’s an example of a styled NotificationWindow content:
Notifications can only be done in Silverlight out-of-browser applications, and are simple to implement in few lines of code.
Video and Sample Code: Notification Window API
At times, you may be interacting with 3rd party (or perhaps your own) services that require authentication information to be passed into the service call. This authentication information may be different than the logged-on user’s current information.
We have enabled providing NetworkCredential information via the ClientHttp networking stack that was introduced in Silverlight 3. For example, to pass a username/password (basic auth) to a service call using this method would be something like this:
Note that we first register the prefix to use the ClientHttp networking stack. The second thing to note is that in WebClient, you still must specify UseDefaultCredentials=”false” even though you are providing new credentials. If you don’t, the default credentials will still be used.
Video and Sample Code: Network Authentication in Web Requests
One of the more significant changes to cross-domain networking comes when you have a trusted application. For services that have a closed cross-domain policy file (via clientaccesspolicy.xml or crossdomain.xml), if your application is a trusted application (elevated permissions), then the requirement for a cross-domain policy file is no longer required.
This only applies to trusted applications.
Video and Sample Code: Network Cross-domain Request in Trusted Application
If you are developing kiosk applications or other Silverlight applications that run in full-screen mode (IsFullScreen=”true”), you have noticed that only a limited set of keyboard input was enabled. In Silverlight 4 trusted applications, any application in full-screen mode can have full keyboard input for things like TextBox or other input controls.
This only applies to trusted applications.
The TextBlock control has a new property called TextTrimming that enables you to use the WordElipse trimming value. When the property is set, any text exceeding the visible limit of the control will be truncated and an ellipsis will be displayed to the user indicating more content.
As items in the Silverlight Toolkit mature in the codebase, these controls move into the core for Silverlight. In this release, ViewBox has reached that level and is now provided in the core. A ViewBox is a container control that aims to help constrain the contents of the ViewBox to a specific size or area and automatically handle scaling, etc.
Video and Sample Code: Using the ViewBox Control
If you are writing an application that requires right-to-left (RTL) support in either text and/or controls, a new attribute for UIElement is now provided for you. The FlowDirection attribute can be applied to represent the element in RTL format.
This can be applied to a higher level in the visual tree and gets automatically applied to child levels.
Video and Sample Code: BiDi and Right-to-left Support
Offline DRM for media playback
The next major wave of PlayReady innovation being built into Silverlight focuses on meeting the top media customer ask for the Silverlight DRM client – support for Offline scenarios. The three key business models targeted for this release of the Silverlight DRM client are Rental, Subscription, and Purchase. The Silverlight PlayReady ecosystem has several features that are valuable for these business models.
PlayReady content protection for Silverlight and VC-1 encoded media has already proven to be a reliable and seamless experience to the user. With Silverlight 4, this content protection is extended to H.264 encoded media assets.
For some scenarios, you may have wanted to be able to drag a file from your desktop or file explorer on to your Silverlight application. By enabling the AllowDrop attribute on UIElement in this release, you can now accommodate those scenarios.
This will be most helpful in file upload applications.
Video and Sample Code: Using Silverlight as a Drop Target
Silverlight adds the IDataErrorInfo interface enables the reporting of validation errors that a user interface can bind to. When an entity implements this interface and the entity is involved in a binding operation, it invokes the indexer to validate the properties. The bound target properties in the UI will receive the error messages and display the validation states if the ValidatesOnDataErrors property is set to true.
IDataErrorInfo is limited to validating on a per property basis. However, Silverlight 4 also adds the INotifyDataErrorInfo interface that allows validation across properties of an entity. It also allows entity objects to enable notification of data errors in the UI. INotifyDataErrorInfo allows developers to provide custom, asynchronous validation support to access server-side validation logic. It exposes a HasErrors property to indicate if there are any errors and has a GetErrors method to retrieve the errors. The ErrorsChanged event is raised when new errors are added. If the binding property ValidatesOnNotifyDataErrors is set to true and the source object implements the interface, the binding engine in Silverlight will listen for the ErrorsChanged event.
Video and Sample Code: Data Validation
Silverlight introduces the ability to bind properties on a DependencyObject (DO) and not just on FrameworkElements. For example, in Silverlight you can bind the rotation angle of a RotateTransform to a Slider control.
This is a highly requested data binding enhancement that should be useful to designers and developers.
If you’ve ever done databinding in XAML using simple things like currency, dates, etc. then you have likely created a ValueConverter. While for simple things it is not difficult, it was often a tedious and repetitive task.
StringFormat is now available to you for a simpler solution for XAML databinding and formatting the output.
Additionally, you can also specify Fallback and TargetNull values in your binding syntax:
The FallbackValue displays a value when the binding operation is unsuccessful, where the TargetNullValue helps provide a value when the result of the binding value is NULL.
This release of Silverlight 4 brings support for the Managed Extensibility Framework (MEF) in the SDK. This is far to important of a topic (and too broad of a topic) to cover in a simple paragraph. Take a look at Glenn Block’s session at PDC (when available) for an in-depth look at this support for MEF in Silverlight.
DataGrid is a commonly used control for building line-of-business applications. Over time, the DataGrid has continually undergone improvement and this release is no different. Take a look at the video for the improvements in the DataGrid control.
Video and Sample Code: DataGrid Improvements
In order to support more fluid user interface experiences, new states have been added to ItemsControl. These new states: BeforeLoaded, Loaded and Unloaded help animate the transition of contents between states in an ItemsControl and provide a more interactive and “fluid” experience to the user.
Silverlight 4 introduces new styling features that allow you to create a style as a resource that can be used implicitly by all elements of a target type. This allows application developers to customize the look across multiple instances of a control and modify the appearance of these control instances by changing the implicit style.
Would result in any <Button> element having a FontSize of 24 and red foreground text.
As browser markets evolve, so must we. During this release cycle we will be officially providing support for the Google Chrome browser. To date, Silverlight has generally worked in Chrome, but we’ll be adding Chrome to our official test/support matrix with this release. We’ve had a working communication group with Chrome to ensure that any questions we’ve had to make sure Silverlight runs well within Chrome are answered.
Summary and Feedback
So there you have it. Some new toys to play around with. What do you think? Please be sure that if you find any issues or compatibility with existing compiled Silverlight applications that you report them in the forum for Silverlight 4 beta.
There are a few other items in the build, so be sure to read the Silverlight 4 Beta information as well as the what’s new documentation and breaking changes documentation provided.
I’m very excited about this release and hope you are as well. I can’t wait to see what you guys and gals do with these new features!
Please enjoy some of these other recent posts...