Chapter 1. Welcome to Silverlight 4

This chapter introduces Silverlight, a Microsoft cross-browser, cross-platform plug-in that allows you to create rich interactive (or Internet) applications (RIAs) for the Web. It begins with a brief look at the evolution of user interfaces, and then provides an overview of Silverlight. You'll learn how Silverlight fits into RIA solutions, the benefits it brings to developers, and the tools involved in developing Silverlight-enabled applications.

The Evolution of the User Interface

Software user interfaces are constantly evolving and improving. I remember back when I was still working with an early version of Windows and looking at Mac OS with envy. Then, I remember seeing Linux systems with radical new desktop interfaces. More recently, I found myself looking again at the Mac OS X Dock (see Figure 1-1) and wanting that for my Windows XP machine—to the point where I purchased a product that mimicked it. I was dedicated to Windows through it all, but I was envious of some of the user experiences the different environments offered.

The Mac OS X Dock feature

Figure 1.1. The Mac OS X Dock feature

The evolution of the user interface continues in the Windows operating system. Perhaps the most prominent difference between Windows 7 and previous versions of Windows is user interface improvements. Microsoft was very intentional on improving the richness of the operating system. One example is the new taskbar, where large icons replace the text descriptions and when the user places the cursor over an icon will display a window thumbnail, as shown in Figure 1-2.

Windows 7 improved taskbar

Figure 1.2. Windows 7 improved taskbar

Another user interface improvement in Windows 7 is the Aero Snap. This feature allows you to easily maximize your window by dragging it to the top of the screen, but it also allows you to drag the window to the left or right edge of the screen in order to tile the window to 50% of the left or right side of the screen as shown in Figure 1-3.

Windows 7 Aero Snap feature

Figure 1.3. Windows 7 Aero Snap feature

These features reflect how operating systems have evolved over the years, but the same evolution pertains to all areas of development, and for just about all industries. It is now expected that applications not only contain necessary features, but that they also have slick user interfaces. However, while rich applications are now expected, it is not necessarily the priority for developers. Over the last decade, there has been a struggle to find the right balance of "rich" and "reach" in applications. If you consider standard desktop applications, the applications are installed on individual client machines. They allow for very rich and responsive user interfaces and additional features, such as offline support. Performance of the application depends on the machine on which it is installed. While desktop applications have a very rich experience, they have very small reach. The application needs to have a code base for each target platform, and every machine needs to have the application installed and maintained.

In contrast, we have web applications, which are HTML-focused programs designed to run within a browser and across platforms. For the Microsoft-based developer, this has recently meant developing with ASP.NET and building web services to offer services over the Internet. The focus of most of the logic and code has been placed on the server for the benefit of application performance. The price has been a poor user interface. These applications had excellent reach, but they were not very rich, as shown in Figure 1-4. Between these two extremes there is a clear gap between the technologies.

Rich and reach application comparison

Figure 1.4. Rich and reach application comparison

To fill this gap, a new development approach has surfaced, as shown in Figure 1-5. This new approach is termed RIA (Rich Internet Applications), which is defined as a web application that has the features and functionality found in traditional desktop applications. Although there are a number of RIA technologies, including Microsoft's Silverlight.

RIA fills the gap between rich and reach applications

Figure 1.5. RIA fills the gap between rich and reach applications

Rich Internet Application Solutions

The concept of RIA has been around for quite some time, but the term rich Internet application was first used in 2002 in a Macromedia white paper. Before then, the terms remote scripting and X Internet were used to describe the concept.

Today, many different solutions fit the description of RIAs, but there is one consistent characteristic: all RIA solutions involve a runtime that runs on the client machine and architecturally sits between the user and the server.

In recent years, the technology that is most commonly used in RIAs is Flash. When Flash was introduced, it brought to the Web rich user experiences never seen before. However, due to the lack of tools allowing Microsoft .NET developers to integrate Flash into their applications, to those developers Flash just seemed like a tool for adding some pretty effects to a web page, but nothing functional.

Then a wonderful thing happened when Adobe purchased Macromedia. All of the sudden, Flash was married to some of the development tools offered by Adobe. Microsoft retaliated by announcing Silverlight, formerly known as Windows Presentation Foundation Everywhere (WPF/E). Silverlight is the technology that many .NET developers have been waiting for.

What exactly is Silverlight? And, what impact does Silverlight actually have on us as .NET developers? Well, I'm glad you asked.

What Is Silverlight?

As I explained in the previous section, all RIAs have one characteristic in common: a client runtime that sits between the user and the server. In the case of Microsoft's RIA solution, Silverlight is this client runtime. Specifically, Silverlight is a cross-platform, cross-browser plug-in that renders user interfaces and graphical assets on a canvas that can be inserted into an HTML page.

The markup used to define a Silverlight canvas is called Extensible Application Markup Language (XAML, pronounced "zammel"). XAML is an XML-based language that is similar to HTML in some ways. Like HTML, XAML defines which elements appear, as well as the layout of those elements. However, unlike HTML, XAML goes far beyond simple element definition and layout. Using XAML, you can also specify timelines, transformations, animations, and events.

The following is an example of a Silverlight canvas defined in XAML:

<UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="FirstLookXaml.MainPage"
        Width="640" Height="480">

        <Canvas x:Name="LayoutRoot" Background="White">
                <Rectangle Height="119" Canvas.Left="75" Stroke="Black"
                   Canvas.Top="92" Width="183"/>
                <Ellipse Height="119" Canvas.Left="347" Stroke="Black"
                 Canvas.Top="92" Width="189"/>
                <Button Content="XAML Rocks!" Height="43" Canvas.Left="233"
                Canvas.Top="285" Width="161"/>
        </Canvas>
</UserControl>

Figure 1-6 shows this canvas in Microsoft Expression Blend, the design tool used to edit and create XAML for Silverlight applications. You can see that this XAML simply defines a rectangle on a canvas, as well as the properties associated with that rectangle, including its name, location, size, color, and border.

This simple example is just intended to give you an idea of what XAML looks like. You'll learn more about XAML in upcoming chapters. For now, let's continue by looking at the benefits of Silverlight.

A basic XAML canvas in Microsoft Expression Blend

Figure 1.6. A basic XAML canvas in Microsoft Expression Blend

Benefits of Silverlight

Naturally, Silverlight offers all of the same benefits of RIAs, but there are a few features that set it apart from other RIA solutions, including the following:

  • It offers cross-platform/cross-browser support.

  • It provides a cross-platform version of the .NET Framework.

  • XAML is a text-based markup language.

  • Silverlight uses familiar technologies.

  • Silverlight offers an Out of Browser and Full Trust option.

  • Silverlight is the main development platform for Windows Phone 7.

  • It's easy to deploy the Silverlight runtime to clients.

Let's take a closer look at each of these benefits.

Cross-Platform/Cross-Browser Support

When ASP.NET was released a number of years ago, one of the benefits touted was cross- browser support. Developers would need to have only one code base, and that code base would work in all modern browsers. For the most part, this is true. No matter which browser you are using, the application will function. However, in order to receive all of the bells and whistles offered by the ASP.NET controls, you must use the latest version of Internet Explorer. If you are using any other browser, you actually get a downgraded version of the web site, which contains fewer features.

Validation controls are a prime example. If you are using a browser that ASP.NET recognizes as an "upscale" browser, you can take advantage of client-side validation. If you are using any other browser, the validation controls still function, but require a postback to the server to do the validation. So, although ASP.NET is cross-browser, users can get different experiences, depending on which browser they are using.

With Silverlight, this changes. Microsoft is once again pulling out the term cross-browser, and also adding cross-platform, and this time they mean it. As a developer, you can create a Silverlight application and rest assured that it will run exactly the same on all supported platforms and browsers.

Currently, two platforms are supported. Naturally, the first is Windows-based platforms, and the second is Mac OS platforms. As for browser support, Internet Explorer, Firefox, Safari and Google Chrome are currently covered.

This leaves one large platform unsupported: Linux. Although Microsoft does not have plans to support Linux, others do. Moonlight is an open source implementation of Silverlight, targeted primarily at Linux based operating systems. Moonlight is part of the Mono project, an open source initiative to develop and run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. Although Moonlight brings Silverlight features to Linux, the project lags behind the aggressive Microsoft release cycles. The latest version of Moonlight is version 3 Preview 6, which comes close to compatibility with Silverlight 3.

Cross-Platform Version of the .NET Framework

Silverlight 1.0 was released by Microsoft in the summer of 2007, but this version supported only Ecma languages that are interpreted in the client. Although Silverlight 1.0 works well for developers who are already familiar with client-side scripting, many developers have their eyes on the second release of Silverlight, version 2. Silverlight 1.0 is more or less in direct competition with Flash—some have called it Microsoft's "Flash killer." However, things really get exciting with Silverlight 2.

Silverlight 2 and beyond contains its own cross-platform version of the .NET Framework, which means it has its own version of the common language runtime (CLR), the full type system, and a .NET Framework programming library that you can use in Visual Studio 2010 to build rich user experiences in the browser.

Use of Familiar Technologies

Microsoft is very good at creating tools that make application development easy. The Visual Studio integrated development environment (IDE) has been around for quite some time, and although new features are continually added to the tool, the environment itself has remained remarkably consistent.

Silverlight development is no different. At the core of developing Silverlight applications is Visual Studio 2010, the latest version in Visual Studio's long history. This gives Silverlight a distinct advantage, as developers do not need to learn how to use a new development environment.

In addition to Visual Studio, Microsoft has a suite of tools called Expression Studio. Included in this suite is Microsoft Expression Blend, which is used to edit and create XAML for Silverlight applications. While Expression Blend looks completely different, it still has many of the same elements as Visual Studio. In addition, Expression Blend works off of the same project as Visual Studio. This means that as you make changes in each of the editors—opening a project in Visual Studio, and then opening the same project in Expression Blend to edit the XAML—the edited files will request to be refreshed when opened again in the other tool.

Small Runtime and Simple Deployment

Since Silverlight requires that a client runtime be installed on the client machine, it is vital that this runtime has a small footprint and downloads quickly. Microsoft worked very hard to get the installation size as small as possible. The developers clearly succeeded with Silverlight 1.0, as the download size is a tiny 1MB. For Silverlight 2, however, they had a harder chore ahead of them, since Silverlight 2 contains its own .NET Framework and object library. Microsoft went to each .NET Framework team and allocated it a size to fit its portion. The end result is astonishing—Silverlight 2 is approximately 4MB in size. In Silverlight 4, even with the large amount of new features that have been added to the Silverlight runtime, the file size is still less than 6MB.

As for pushing the Silverlight runtime out to clients, Microsoft has provided a very easy detection mechanism. If the client does not have the proper Silverlight runtime installed, it will display a logo, similar to the one shown in Figure 1-7.

Silverlight runtime required logo

Figure 1.7. Silverlight runtime required logo

When users click the icon in the logo, the Silverlight runtime will start to download. Once the runtime is finished installing, the Silverlight application is immediately available to the user.

The Silverlight Development Environment

In the past, setting up an environment to work with Microsoft's latest and greatest has been relatively straightforward, typically involving only the setup of the latest version of Visual Studio and the appropriate software development kit. However, with Silverlight, the situation is quite a bit different due to the introduction of many new tools. Let's look at the tools involved in setting up a Silverlight 4 development environment.

  1. Visual Studio 2010: As noted, this is the latest version of Microsoft's IDE, the successor to Visual Studio 2008 (see Figure 1-8). For your Silverlight environment you should install Visual Studio 2010, which automatically installs Microsoft .NET Framework 4. Chapter 2 covers Visual Studio 2010 in more depth.

    Microsoft Visual Studio 2008

    Figure 1.8. Microsoft Visual Studio 2008

  2. Silverlight Tools for Visual Studio 2010: This is a package that adds the necessary items to Visual Studio to teach it how to handle Silverlight projects. The package includes a number of items, some of which are listed below:

    • Silverlight 4 Runtime: Required on every computer that wishes to view a Silverlight-enabled web application.

    • Silverlight 4 Software Development Kit: This SDK is a collection of samples, Silverlight QuickStarts, documentation, and controls that are used to develop Silverlight applications.

    • Silverlight Project Templates for Visual Studio 2010: This adds the Silverlight templates in Visual Studio. As an example, it will add the template that enables you to create a Silverlight project from the "Add New Project" in Visual Studio.

  3. Expression Blend 4: The next thing to install for your Silverlight development environment is Expression Blend (see Figure 1-9). Expression Blend a design tool for building XAML based interfaces including Windows Presentation Foundation (WPF) and Silverlight. Expression Blend is not required for creating Silverlight solutions, but provides a richer designer than does Visual Studio 2010. Expression Blend 4 is covered in detail in Chapter 11.

    Microsoft Expression Blend 4

    Figure 1.9. Microsoft Expression Blend 4

  4. Silverlight 4 Toolkit. The Silverlight Toolkit is an open source CodePlex project whose goal is to develop additional controls for Silverlight applications. Controls within the toolkit are assigned a status that describes their maturity as controls and the controls are supported by the open source community. You can download the toolkit for Silverlight 4 at http://www.codeplex.com/ silverlight. The Toolkit is discussed in Chapter 6.

New Features in Silverlight 4

Silverlight continues to evolve and Microsoft continues to add new features to Silverlight in each version. There are many new features introduced in Silverlight 4. This section will go over some of those new features and will indicate where those features are discussed in this book.

  • Elevated Trust Applications: In releases of Silverlight prior to version 4, Silverlight applications were restricted to a sandbox and did not have access to a client's devices or hard drive. In Silverlight 4 developers have an option to create elevated trust applications that will gain access to devices on the client machine as well as the client's hard drive. Elevated Trust Silverlight Applications are discussed in Chapter 16.

  • New Controls: With each new version of Silverlight, more and more controls are added. This is no different with Silverlight 4, which has added a number of new controls such as the RichTextArea and ViewBox control. These controls are discussed in Chapters 3 to 6.

  • System Integration and Device Support: One other short-coming of past releases of Silverlight is the lack of device level support. In Silverlight 4, developers can now access a user's attached web camera and/or microphone with just a few lines of code. In addition to web cams and microphones, additional support for mouse wheel and right mouse click has also been added to Silverlight 4. Device Support is discussed in Chapter 10.

  • Printing Support: One of the most popular new features in Silverlight 4 is the added support for client-side printing. Silverlight 4 includes an extensible printing API that will allow developers to enable client printing from a Silverlight application. Developers can either print the contents of a visual tree from within the Silverlight application, or they can construct a custom visual tree that will allow end users to print customized views of data directly from Silverlight.

  • Custom Window Chrome: One of the biggest features of Silverlight was the ability to run Silverlight applications out of the browser. However, it didn't take long until developers were immediately requesting the ability to allow their out of browser Silverlight Applications to escape the standard windows chrome. In Silverlight 4 developers can create their own custom chrome for their applications so their entire application can have a consistent look, including the application's frame.

  • Additional Browser Support: Silverlight 3 added support for Safari browsers, but one popular browser was still unsupported. Although Silverlight 3 generally worked with the Google Chrome browser, there was no official support for Google's browser. Silverlight 4 adds official support for Google Chrome, which means that Silverlight 4 is supported in virtually all mainstream browsers.

  • Silverlight as Drop Target: If you are used to using desktop applications, you are also probably familiar with the ability to drag files onto the application to perform some task. This is something that has not been possible in previous versions of Silverlight. Silverlight 4 adds the ability to drag files onto out of browser Silverlight applications. This is another feature that comes nearly directly from WPF. Currently only files are supported, but it is clear in the implementation that additional drag types are on the way in future releases of Silverlight. Read more about enabling your Silverlight applications as drop targets in Chapter 10.

  • Notification Pop-ups (Toast Window Support): At times it is very useful to notify the user of events in your application. The standard that has formed in the industry is notification pop-ups (also referred to as toast). These are small message windows that appear in the bottom right of the screen in Windows and in the top right hand part of the screen on Mac OS. Silverlight 4 adds support for toast messages that allow developers to add notification to Silverlight applications.

  • Keyboard Access in Full Screen: If you have multiple monitors, you have most certainly noticed that you cannot access your keyboard if you are working with a Silverlight application in full screen mode. If you do, the application will automatically escape out of full screen mode. Silverlight 4 fixes this problem, by adding support for keyboard access in full screen mode.

Improved Performance

With each new release of Silverlight, besides adding a number of new features, Microsoft has thrived to continue to improve the performance of the Silverlight runtime. Silverlight 4 continues this trend and offers significant performance improvements over pervious Silverlight versions. In fact, benchmarks are indicating that Silverlight 4 is twice as fast as Silverlight 3, and loads approximately 30% faster than its previous version.

Summary

In this chapter, you looked at the evolution of user interfaces in applications, as well as the history of RIAs. I then introduced Silverlight, talked about the benefits it brings to developers today, and how it fits into RIA solutions. Finally, you learned about the tools involved in developing Silverlight-enabled applications.

Now it is time to get your hands dirty and start building some Silverlight applications! In the next chapter, I will provide an introduction to Microsoft Visual Studio 2010, one of the primary tools used to build Silverlight applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset