This article describes the enhanced and new features of Silverlight 4.0
Silverlight 4.0 Features
Fluid UI: 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.
Full Screen Keyboard Access: 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.
More Trust Applications: 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:
It is important to note that this trusted application request still does not involve installing any additional runtime for the use. It is a part of the Silverlight 4 runtime – no additional download/framework would be required.
IDataErrorInfo and asynchronous validation: 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.
DependencyObject Binding: 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. Sample Code:
StringFormat, TargetNullValue, and FallbackValue: 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. Sample Code:
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.
Tooling: With Visual Studio 2010, you finally have 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 as well. What is great about the Silverlight tools in VS2010 is that the databinding support is pretty rich in the designer surface as well.
Print API: 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, a printing API is provided that is 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.
Right Click Event Handling: 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, you now have 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. Here's an sample output of ‘right click' menu:
Local File Access: 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).
COM interoperability: 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.
Notification (aka “toast") API: Notification mechanism 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:
Text Trimming: 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. Sample Code:
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="The quick brown fox jumped over the tall white fence" TextTrimming="WordEllipsis" Width="120" />
Right-to-left support in controls: 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. Sample Code:
Google Chrome support: During this release cycle Silverlight will be officially providing support for the Google Chrome browser. Silverlight has generally worked in Chrome, but in this release Chrome will be added to official test/support matrix.
Managed Extensibility Framework (MEF): Managed Extensibility Framework (MEF) means building maintainable/pluggable RIA apps just got a whole lot easier. The Managed Extensibility Framework (MEF) is a new library in Silverlight 4 for building RIAs that can be incrementally extended. With MEF you extend your apps in a declarative fashion and let MEF do the plumbing rather than writing all the plumbing code yourself.
It's for you and your dev team: You can add and replace functionality to the system without having modified existing code. This means you and your QA team are happy because you don't have to worry about introducing bugs into the existing code base.
It's for your customers: MEF allows you to design applications and libraries that can be extended by third-parties after they have been deployed.
Always there, always ready: In Silverlight, MEF is ready to go whenever and wherever you need it. You don't have to be an acrobat, or have a master's degree in complexity, you just do it.