1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình .net 4.0 và visual studio 2010 part 48 ppt

6 249 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

CHAPTER 14    327 Silverlight Introduction Availability: Framework 3.5sp1 Onward “Silverlight is a new web presentation technology that is created to run on a variety of platforms. It enables the creation of rich, visually stunning and interactive experiences that can run everywhere: within browsers and on multiple devices and desktop operating systems (such as the Apple Mac).” http://silverlight.net/content/GetStarted.aspx Some might say that Silverlight is Microsoft’s version of Adobe’s Flash and Flex products. This doesn’t really do it justice, though. Silverlight has a number of compelling features that make it an ideal choice for creating web applications with the functionality traditionally only found in desktop applications. These applications are known as Rich Internet Applications (or RIA to its friends). Silverlight offers the following: • Ability to use the .NET development tools you know and love • Utilize many of the .NET framework libraries in your applications (for security reasons, not everything is available) • An easy-ish path to convert web applications to desktop (WPF) applications if required in the future (also check out Silverlight 3’s offline capabilities in Chapter 15) • Great media-streaming capabilities • Support for designers (more prevalent in Blend) Although Silverlight was available for earlier versions of .NET and Visual Studio, I decided to include a brief introduction because Silverlight was released between VS2008 and VS2010, and I suspect that many developers are not aware of how easy it is to use. I believe Silverlight will grow in importance and is something that all .NET developers should at least be aware of. Silverlight versus Flash When Silverlight was first released, it was inevitable that it would be compared to Adobe Flash (and Flex) due to its similar function. Although there is overlap between the two products, I don’t think Microsoft’s primary intention was to just launch a competing product. CHAPTER 14  SILVERLIGHT INTRODUCTION 328 Silverlight’s development was the obvious offshoot of WPF, and there was no satisfactory technology for the Microsoft developer to create RIAs prior to its release. Options such as ActiveX controls or embedded Windows forms suffered from being difficult to develop and debug, were not cross-platform, and had security and deployment issues. For a taste of just what is possible using Silverlight, take a look at the upcoming Microsoft Office Online application (http://channel9.msdn.com/posts/PDCNews/First-Look-Office-14-for-Web/). Office Online utilizes Silverlight to provide online versions of Word, Excel, and PowerPoint. Perhaps the biggest advantage offered by Silverlight is that applications can be written using the .NET framework and existing Microsoft tools such as Visual Studio. This immediately lowers the entry barrier to new developers and gives them access to much more functionality. Although Flash is almost certainly installed on more browsers than Silverlight, at the time of writing, Microsoft is in a strong position to encourage uptake of Silverlight (subject to future possible antitrust legislation!). It is hard to get accurate statistics about Silverlight uptake, but the sites http://www.riastats.com/ and http://www.statowl.com/silverlight.php are well worth a look. At the time of writing, they indicate that roughly 25 percent of browsers have some version of Silverlight installed. Adobe indicates that it has a much higher uptake, which is to be expected with a more mature product: http://www.adobe.com/products/player_census/flashplayer/. Silverlight in the Real World An impressive example of a Silverlight application is “Descry: A Website Named Desire” that was created for the Mix conference. This web site illustrates the web site development process (see Figure 14-1) and is available online at http://www.visitmix.com/labs/descry/awebsitenameddesire/. Figure 14-1. Descry example project from Mix team (http://www.visitmix.com/labs/ descry/awebsitenameddesire/) CHAPTER 14  SILVERLIGHT INTRODUCTION 329 One of the earliest but still very impressive uses of Silverlight is on the Hard Rock Café’s memorabilia page. If you haven’t seen it, go to it now at (http://memorabilia.hardrock.com/). The page shows rock memorabilia items owned by the Hard Rock café (see Figure 14-2). The user can fluidly zoom in and out to display more detail of any individual item. This site was created with Silverlight and a technology called Deep Zoom.  NOTE Deep Zoom is freely available for your use if you want to create a similar application: http://msdn. microsoft.com/en-us/library/cc645050(VS.95).aspx. Although a relatively new technology, Silverlight has already been put to the test when it was used very successfully to stream coverage of the Beijing Olympics for NBC. Brian Goldfarb (group product manager) said Silverlight streamed more than 250TB of data over this period (http://www.eweek.com/ c/a/Application-Development/Microsoft-Proving-Ground-Silverlight-at-the-Olympics/). Interested? You should be. Take a look at the technology stack Silverlight is built on. Figure 14-2. Hard Rock Café memorabilia page (http://memorabilia.hardrock.com/) CHAPTER 14  SILVERLIGHT INTRODUCTION 330 WPF As part of.NET framework version 3.0, Microsoft released Windows Presentation Foundation (WPF): a new way of creating UIs for applications. Silverlight uses a subset of the full WPF and .NET framework. You will find some classes and methods unavailable, and anything with the SecurityCritical attribute cannot be used. Why not use the full WPF and .NET framework? • Silverlight is a browser plug-in, so it needs to be small. • Some WPF functionality might present a security risk when run in the browser. • Not all WPF functions are cross-platform. XAML Silverlight applications are developed using eXtensible Application Markup Language (XAML). XAML is an XML-based language that is used to describe objects. XAML is used in other areas of .NET such as WPF and WCF. You can expect to see Microsoft making increasing use of XAML for many different purposes in the future. Silverlight Requirements and Installation To develop Silverlight applications, you will require one of the following: • Visual Studio 2008 and Silverlight Tools for Visual Studio and .NET 3.5sp1 • Visual Studio 2010 Expression Blend The design time support for WPF and Silverlight applications is greatly improved in Visual Studio 2010 (see Chapter 17), but for serious Silverlight development a separate product called Expression Blend is almost essential. Expression Blend (written using WPF) is very much aimed at designers and eases tasks such as layout, animation, and customization of controls. You will still need to edit code in Visual Studio, but Visual Studio and Blend play well together so you can have both open at the same time and skip between them. When a designer and a developer work at the same time on an application, there can be issues as one developer’s changes overwrite the others. Microsoft has tried to address this with a declarative data binding syntax and design of Blend. I am not sure they have fully achieved this lofty aim, but it is a step in the right direction. If you want to see whether Blend is worth using for you, download the free trial version of Blend from the main Silverlight.net site at http://silverlight.net/GetStarted/. CHAPTER 14  SILVERLIGHT INTRODUCTION 331 Figure 14-3. Expression Blend Designer Creating a New Silverlight Project Get started creating a new Silverlight project. 1. Open Visual Studio. 2. Select File➤ New Project. 3. Select the C# node and then the Silverlight node. 4. Select Silverlight Application. 5. Call your project Chapter14.HelloSilverlight. 6. Make sure the “Host the Silverlight application in a new Web site” option is selected (this will be essential later on). 7. Click OK. Visual Studio will now create a Silverlight solution for you to use. CHAPTER 14  SILVERLIGHT INTRODUCTION 332 Project Structure Visual Studio has created two projects (see Figure 14-4): • Chapter14.HelloSilverlight • Chapter14.HelloSilverlight.Web Why two projects? • Chapter14.HelloSilverlight.Web acts as a host or test harness for the application. • Chapter14.HelloSilverlight contains the Silverlight code. In the future, you might not want to create a separate hosting project. If so, don’t check the add a new ASP.NET web project option. If you do this then Visual Studio will dynamically generate a page to display your Silverlight application when run (see Figure 14-4). Figure 14-4. Silverlight default project setup . applications, you will require one of the following: • Visual Studio 200 8 and Silverlight Tools for Visual Studio and .NET 3.5sp1 • Visual Studio 201 0 Expression Blend The design time support for. available for earlier versions of .NET and Visual Studio, I decided to include a brief introduction because Silverlight was released between VS 200 8 and VS 201 0, and I suspect that many developers. Visual Studio will now create a Silverlight solution for you to use. CHAPTER 14  SILVERLIGHT INTRODUCTION 332 Project Structure Visual Studio has created two projects (see Figure 14- 4):

Ngày đăng: 01/07/2014, 21:20

TỪ KHÓA LIÊN QUAN