12 New Features in Silverlight 4

Introduction

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.

Prerequisites

To develop Silverlight 4 applications, you should have the following installed in your system:

  • 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:

  1. 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();
    
  2. 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.
  3. 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.
  4. 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.
  5. Support for accessing local files and folders on the user's system--you no longer need to depend on the OpenFileDialog and SaveFileDialog to 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.
  6. 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 ComAutomationFactory API. 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;
    

  7. 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.xaml file to allow requests for elevated permissions while installing the out-of-browser application:

    <OutOfBrowserSettings.SecuritySettings>
        <SecuritySettings ElevatedPermissions="Required" />
    </OutOfBrowserSettings.SecuritySettings>
    

  8. Support for Hosting HTML content using WebBrowser control - Silverlight 4 now allows support for hosting HTML content using the new WebBrowser control. 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:

    TestBrowserControl.NavigateToString("<div><b>Joydip Kanjilal</b></div>");

    You can also navigate to a URL using code similar to what is shown in the code snippet below:

    TestBrowserControl.Navigate(new Uri("http://aspadvice.com/blogs/joydip"));
    

  9. Support for RichTextArea - Silverlight 4 includes an editable text control called RichTextArea that provides support for storing rich text with styles and sizes. The RichTextArea control 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:

    MyRichTextAreaControl.Selection.SetPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
    

    And, here's how you can underline the text in the control:

    MyRichTextAreaControl.Selection.SetPropertyValue(TextElement.TextDecorationsProperty, TextDecorations.Underline);
    

  10. 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.");
    

  11. 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 PrintDocument class in the Print API of Silverlight 4 to leverage the printing features.
  12. 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/Down events. 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);
    

Summary

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!

References

http://www.microsoft.com/silverlight/
http://www.silverlight.net/getstarted/silverlight-4/
http://forums.silverlight.net/forums/59.aspx

http://www.silverlight.net/community/blogarchive/microsoft/1/

Related Articles



About the Author

Joydip Kanjilal

Microsoft Most Valuable Professional, Author and Speaker. Featured in "MSDN Featured Developer of the Fortnight (India)" a number of times. Winner of Community Credit Awards at www.community-credit.com several times. Authored numerous books and articles in Microsoft .NET and its related technologies. Authored the following books:-- ASP.NET 4.0 Programming (Mc-Graw Hill Publishing) Entity Framework Tutorial (Packt Publishing) Pro Sync Framework (APRESS) Sams Teach Yourself ASP.NET Ajax in 24 Hours (Sams Publishing) ASP.NET Data Presentation Controls Essentials (Packt Publishing)

Comments

  • WPF

    Posted by danlb on 07/28/2010 08:39am

    "Silverlight, formerly known as Windows Presentation Foundation (WPF)" Actually Silverlight used to be called Windows Presentation Foundation/Everywhere (WPF/E). WPF is still an active technology used for doing desktop applications.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

  • Not long ago, security was viewed as one of the biggest obstacles to widespread adoption of cloud-based deployments for enterprise software solutions. However, the combination of advancing technology and an increasing variety of threats that companies must guard against is rapidly turning the tide. Cloud vendors typically offer a much higher level of data center and virtual system security than most organizations can or will build out on their own. Read this white paper to learn the five ways that cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds