Over the past few years, Silverlight, formerly known as Windows Presentation Foundation (WPF), has quickly become the technology of choice for developing the next generation of cross-browser, cross-platform Rich Internet Applications (RIAs). Silverlight is a browser plugin that promotes a collaborative development environment of rich online media content that enables developers and designers alike to integrate multimedia and graphics into web pages within the context of Microsoft .NET frameowrk's managed environment. This article takes a look at the striking new features in Silverlight 4 and how they can be used in application development to design and implement applications with intuitive user interfaces with support for rich graphics and media.
Why Silverlight 4?
Silverlight 4 provides a great tool for designers and developers to build cutting edge applications with awesome multimedia and graphics. In Silverlight 4, you have excellent support for printing, rich reporting and charting, support for web camera and microphone, support for COM automation, support for local file access, support for new languages, rich text editing, and, improved support for data binding to name a few. Also, you can easily integrate your Silverlight 4 applications with back-end systems and server products that include SharePoint. Silverlight 4 is amazingly feature rich and its evolution will increase the demand for building LOB applications using Silverlight 4.
- Microsoft Visual Studio 2010 RC or higher
- Silverlight 4 Tools for Microsoft Visual Studio 2010
Note that If you previously installed the Silverlight 4 Beta or RC build on your system, you should uninstall any previous version of Silverlight in your system and the "Update for Microsoft Visual Studio 2010 (KB976272)" package prior to installing the Silverlight 4 Tools for Microsoft Visual Studio 2010. Also, if you install Silverlight 4 Tools for Visual Studio 2010, you need not install the Silverlight 4 SDK seperately.
Top 12 New Features in Silverlight 4
There are plenty of new and exciting features in Silverlight 4. Here is a list of the top 12 new and exciting features in Silverlight 4:
- Support for Webcam and Microphone - You can use Silverlight 4 to build applications that can have the capability of sharing video and audio. You can use the following code snippet to get a list of all the availble audio and video sources in your system:
AudioSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices(); VideoSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
- Support for Multicast Networking - This is a feature that enables the enterprises to cut down on the streaming broadcast events, meetings and trainings and also interoperates seamlessly with the existing Windows Media Server streaming infrastructure.
- Optimized Performance - Applications built using Silverlight 4 are amazingly fast it's much faster than the equivalent Silverlight 3 applications, thanks to the new Just In Time Compiler. Also, Silverlight 4 applications start much quicker compared to applications built using the earlier versions of Silverlight.
- Support for Better Developer tools in Microsoft Visual Studio 2010 - Silverlight 4 Tools for Visual Studio 2010 are great. You now have an excellent design surface, rich property grids, full intellisense support for your XAML code, drag and drop support for databinding controls, etc.
- Support for accessing local files and folders on the user's system--you no longer need to depend on the
SaveFileDialogto access files and folders in your system from your Silverlight application. Silverlight 4 now allows you to access the folders in your system directly. The folders that can be accessed include all the "My" folders like, MyDocuments, MyVideos, MyMusic, etc.
- Support for COM Interoperability - You can now use Silverlight 4 to interoperate with COM interfaces. As an example, you can communicate with Microsoft Office applications from Silverlight now seamlessly using the
ComAutomationFactoryAPI. Here is a code snippet you can use to make your Silverlight 4 applications talk to Microsoft office:
dynamic excel = ComAutomationFactory.CreateObject("Excel.Application"); excel.Visible = true; dynamic workbook = excel.workbooks; workbook.Add(); dynamic sheet = excel.ActiveSheet;
Similarly, you can use the following code snippet to make your Silverlight 4 application talk to Microsoft Word:
dynamic word = ComAutomationFactory.CreateObject("Word.Application"); word.Documents.Add(); word.Visible = true;
- Enhanced Support for Out-of-browser applications - Silverlight 4 extends the capability of Silverlight 3 to provide a seamless support for RIA applications to work on the desktop without the need of any additional code or runtime. Support for Out-of-browser applications was initially provided in Silverlight 3. Silverlight 4 provides enhanced support for Out-of-browser applications, it has now relaxed some of the sandbox restrictions while executing such applications. The Silverlight 4 runtime now allows the following, under elevated permissions while executing out-of-browser applications:
- Support for Cross domain network access with policy file check
- Support for accessing user's folders
- Support for COM Interop
- Support for HTML hosting
Note that you should specify the following configuration in the
ApplicationManifest.xamlfile to allow requests for elevated permissions while installing the out-of-browser application:
<OutOfBrowserSettings.SecuritySettings> <SecuritySettings ElevatedPermissions="Required" /> </OutOfBrowserSettings.SecuritySettings>
- Support for Hosting HTML content using WebBrowser control - Silverlight 4 now allows support for hosting HTML content using the new
WebBrowsercontrol. Here is an example that shows the markup code of the WebBrowser control:
<WebBrowser x:Name="TestBrowserControl" Width="800" Height="600" />
You can then use the
NavigateToString()method of the WebBrowserControl as shown below:
You can also navigate to a URL using code similar to what is shown in the code snippet below:
- Support for RichTextArea - Silverlight 4 includes an editable text control called
RichTextAreathat provides support for storing rich text with styles and sizes. The
RichTextAreacontrol in Silverlight 4 enables you to load and save the content as basic HTML too. Here is how the markup code of this control looks like:
<RichTextArea x:Name="MyRichTextAreaControl" Grid.Row="1" />
Now, to make the content in the RichTextArea control bold, you can use the following code:
And, here's how you can underline the text in the control:
- Support for Clipboard API - The new Clipboard API in Silverlight 4 enables you to paste content from the Clipboard to a Silverlight application. Here is a code snippet that illustrates how you can store text in the system's Clipboard:
Clipboard.SetText("This is a sample text.");
- Support for Printing API - Silverlight 4 provides an extensible Printing API that can be used to create a virtual visual tree to print from Silverlight applications directly. You can use the
PrintDocumentclass in the Print API of Silverlight 4 to leverage the printing features.
- Support for Handling Right-click Mouse Events - Event handling in Silverlight is much simpler and flexible. You can now use Silverlight 4 to design and implement applications with context-style menus using the
MouseRightButtonUp/Downevents. Here is how you can attach event handlers for handling events for the right mouse button:
SampleControl.MouseRightButtonDown += new MouseButtonEventHandler(RectangleContextDown); SampleControl.MouseRightButtonUp += new MouseButtonEventHandler(RectangleContextUp);
In this article we took a quick tour of the new features in Silverlight 4. I will present discussions on these and other striking features of Silverlight 4 in my future articles here. So, stay tuned!