Silverlight 5 in C#

所需积分/C币:10 2016-06-17 15:08:38 18.44MB PDF

Silverlight 5 in C#
Contents at a glance About the author About the technical reviewer ■■■■■■■ ■■■■■■■ ■ Acknowledgments Introduction Chapter 1: Introducing Silverlight Chapter 2: XAML B RRRBBBRRRRIIE ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 33 Chapter 3: Layout. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ n61 Chapter 4: Dependency Properties and Routed Events RR IRmin 107 Chapter 5: Elements mmma u143 Chapter 6: The Application Model mmm 203 Chapter 7: Navigation ma. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ a233 Chapter 8: Shapes and Transforms ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 263 Chapter 9: Brushes, Bitmaps, and Printing m BI MaImaImImaImImIRma 315 Chapter 10: Animation Basics mmm mmmmamaa 351 Chapter 11: Advanced Animation ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■I 379 Chapter 12: Sound, Video, and Deep Zoom mmmmmmmmmmmmmmaIma 413 Chapter 13: silverlight 3D ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4G9 Chapter 14: Styles and Behaviors ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ nu513 Chapter 15: Control Templates ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口 541 Chapter 16: Multithreading. mmmmaan n585 Chapter 17: Browser Integration man 607 Chapter 18: Out-of-Browser Applications.. u633 Chapter 19: ASP. NET Web Services Hm BERIRRERRRIBIRRRERIIRRI 683 ■ CONTENTS Chapter 20: Data Binding ■■■■■■■ ■■■■■■■ u715 Chapter 21: Data Controls. mn u769 Chapter 22: File Access n829 Chapter23: Networking,,,,围围863 Index Introduction Silverlight is a framework for building rich, browser- hosted applications that run on a variety of operating systems. Silverlight works its magic through a browser plug-in. When you surf to a web page that includes Silverlight content, this browser plug-in runs, executes the code, and renders that content in a specifically designated region of the page The important part is that the Silverlight plug-in provides a richer environment than the traditional blend of hTMl and Java Script that powers ordinary web pages. Used carefully and artfully, you can create Silverlight pages that play video, have hardware accelerated 3D graphics, and use vector animations Understanding silverlight Silverlight uses a familiar technique to go beyond the capabilities of standard web pages: a lightweight browser plug The advantage of the plug-in model is that the user needs to install just a single component to see content created by a range of different people and companies Installing the plug- in requires a small download and forces the user to confirm the operation in at least one security dialog box. It takes a short but definite amount of time, and it's an obvious inconvenience. However, once the plug-in is installed, the browser can process any content that uses the plug-in seamlessly, with no further prompting Figure l shows two views of a page with Silverlight content. At the top is the page you ll see if you dont have the Silverlight plug-in installed. At this point, you can click the Get Microsoft Silverlight picture to be taken to Microsoft's website, where you'll be prompted to install the plug-in and then sent back to the original page. On the bottom is the page you'll see once the Silverlight plug-in is installed ■| NTRODUCTION e ElQuintero, net-Tetrislight- Windows Internet Explorer 巴回_x 5h 4 @EIQuintero,net-Tetrislight 位· t:Page0Igos Microsoft To view this content, please install Microsofts Silverlight Click now to install QUICK DOWNLOAD /30 SECOND INSTALL L e Internet Protected Mode:On 代100% e EIQuintero net-Tetrislight - Windows Internet Explorer ElQuintero. net- Tetrislight 合·h· BPage像Tgo NEST neg⑥ di ad Score 8 G e Internet Protected Mode: On 4.100% igure 1. Installing the Silverlight plug-in ■| NTRODUCTION Note At the time of this writing Silverlight 4 is installed on an estimated 75% of Internet-connected computers (including desktop and mobile devices). The share is higher if you consider only Windows operating systems or Interent Explorer browsers. Although this is impressive, it pales in comparison to Flash, which has version 10 or betterinstalledonastaggering96%ofallwebdevices( Silverlight System Requirements With any Web-centric technology, it's keenly important to have compatibility with the widest possible range of computers and devices. And although Silverlight isn't completely cross-platform, its compatibility stacks up well on the majority of desktop computers Currently, Silverlight supports Windows computers: Silverlight works on PCs with Windows 7, windows vista and Windows XP. The minimum browser versions that Silverlight supports are Internet Explorer 6, Firefox 1.5, and Google Chrome 4.0. Silverlight will also work in Windows 2000, but only with Internet Explorer 6. Other browsers, such as Opera and Safari (for Windows), arent currently supported Mac computers: Silverlight works on Mac computers with OS 10.4.8 or later provided they have intel hardware(as opposed to the older PowerPC hardware The minimum browser versions that Silverlight supports are Firefox 2 and Safari 3 Silverlight does not run on mobile Apple devices, which includes the iPhone, iPod Touch, and ipad Linux computers Although Silverlight 5 doesnt work on Linux, the mono team has created an open-source Linux implementation called Moonlight. The last officially released version supports Silverlight 2 applications, although there is also a released preview version that supports Silverlight 4. Progress is slow, and it's uncertain when(and if) there will be a Moonlight that supports Silverlight 5 Windows Phone: Silverlight is also one of two development frameworks for Windows Phone 7(the other being the game-focussed Microsoft XNA). However, developing for Windows phone raises some unique considerations, and there are some subtle feature differences. To learn more about WP7 development, you can refer to a dedicated book, like Pro Windows Phone 7 Development. Installing Silverlight requires a small-sized setup(around 6MB)that's easy to download. That allows it to provide an all-important"frictionless"setup experience, much like Flash Silverlight vs. Flash The most successful browser plug-in is Adobe Flash, which is installed on over 90 percent of the world's web browsers. Flash has a long history that spans more than ten years, beginning as a straightforward tool for adding animated graphics and gradually evolving into a platform for developing interactive ■| NTRODUCTION It's perfectly reasonable for. neT developers to create websites that use Flash content. However, doing so requires a separate design tool, and a completely different programming language (Action Script) and programming environment (Flex. Furthermore, there's no straightforward way to integrate Flash content with server-Side. NET code. For example, creating Flash applications that cal NET components is awkward at best. Using server-side. NET code to render Flash content (for example, a custom ASP. NET control that spits out a Flash content region) is far more difficult That's where Silverlight fits into the picture. Silverlight aims to combine the raw power and cross platform support of Flash with a first-class programming platform that incorporates the fundamental concepts of. NET. As a result, developers can write client-side code for Silverlight in the same language they use for server-side code(such as C# and vB), and use many of the same abstractions (including streams, controls, collections, generics, and LINQ In short, for. nET developers Silverlight is both a more convenient and a more powerful choice for rich Internet applications Silverlight vs. HTML5 When Silverlight was first created it was intended as an all-purpose way to build rich web pages and a competitor to Adobe Flash. However, in the several Silverlight versions since, the world has changed Although Adobe flash is still supported by virtually every desktop computer, it's been locked out of popular apple products like the iPhone and iPad. As a result, the mobile world is gravitating to different solutions, including native applications(which are limited to just one operating system)or hTML5 HTML5 promises(when it's fully adopted) still fall far short of the features that are available today in at a broad consensus exists that hTmL5 is the future of the Web, someday. However, the features that Flash and Silverlight. For some applications, these shortcomings dont matter. And, without doubt, the capabilities of HTML5 will strengthen in the future. But in the meantime, developers are forced choosing between features now, if they need them (in which case theyre likely to pick Silverlight) and the broadest possible compatibility for all computers and mobile devices (in which case they ' ll probably prefer HTML5). This dilemma is also described as rich versus reach. Silverlight is the rich side of this equation--it gives applications the most powerful and mature feature set. hTML5 is the reach, because it embraces every modern desktop browser. Because of this upheaval, many Silverlight developers are uncertain about exactly where their favorite technology fits into the world of web development. And while the future is far from certain, here are a few points to keep in mind htML5 isnt quite here yet: hTML5 support lags inin Internet Explorer. Many html5 features are promised for the not-yet-released IE 10, some features are available in the relatively recent IE 9, but IE 8 has no htML5 smarts. This is a problem, because ie 8 is the best version of ie that can run on the still- widespread Windows XP platform For all these reasons, htML5 remains currently has less support than Silverlight, and this situation may take years to change Silverlight has features that have no HTML5 equivalent: Even in the browsers that offer the best possible htML5 support fall behind Silverlight in a few key ares. They cant offer the same video streaming features, the same hardware-accelerated graphics, or the same deep networking support Nor do they support file access, out-of-browser applications, or the ability to call Windows system components. And it's hard to imagine htML5 ever duplicating some of Silverlight,'s more specialized features, like the PivotViewer control that fuses together data filtering, fluid animations and image scaling in one easy-to-use package( Chapter 21) Silverlight has a higher-level programming API: Features like data binding, styles, and templates may not be essential for building an application, but they are important for building one quickl XXXIlL ■| NTRODUCTION and efficiently. Many things that are possible in hTML5 are a managibility nightmare in all but the most disciplined hands. The JavaScript language is notoriously lax in letting syntax errors slide, all animation routines must be written by hand and multithreading support is clumsy at best Silverlight has top-tier development tools: Thanks to Visual Studio, you can build a silverlight application just as easily as you build a desktop program. Add Expression Blend to the picture, and you also have a way to define and customize rich graphical effects, like animations Silverlight offers asP. NET integration: In particular, Silverlight makes it easy to query server-side databases through a web service. This state of affairs has led some developers to speculate that even when htML5 does finally conquer the world, Silverlight will remain as a first choice for line-of- business development inside closed company networks No one's quite sure of Silverlight,'s future. It may continue on as a first-choice platform for. NET developers creating business applications, or it may gradually transition into a more specialized tool for cutting-edge games and video players. One thing is settled, however--Silverlight will never replace HTML as the main language for creating traditional, public websites--nor does it intend to Silverlight vs Metro(and windows 8) When Microsoft announced windows 8, complete with yet another programming model for rich client applications, Silverlight developers paused. Some wondered if that technology--named Metro-would be an eventual Silverlight replacement. The answer is clearly"no. Metro is designed to facilitate an entirely different sort of application:a Windows 8-powered tablets In a very real sense, Metro is a competitor to native apps on the iPad ,as well as a potential successor to Microsoft's other rich desktop programming framework, WPF(see the next section). However, Metro applications have no ability to run on non-Microsoft platforms-or any version of Windows other than Windows 8. For that reason, they are of little interest to Silverlight developers In the future, the range of Silverlight applications may narrow, squeezed between cross-platform HTML5 applications that are gradually growing more sophisticated, and native Metro or iPad applications for mobile devices. However, today Silverlight still occupies the very important space between these other technologies Silverlight and wpf One of the most interesting aspects of Silverlight is the fact that it borrows the model WPF uses for rich, client-side user interfaces WPF is a toolkit for building rich Windows applications. WPF is notable because it not only simplifies development with a powerful set of high-level features, it also increases performance by rendering everything through the Directx pipeline. To learn about WPF, you can refer to Pro WPF in C# 2010 (Apress Silverlight obviously cant duplicate the features of wPF, because many of them rely deeply on the capabilities of the operating system, including Windows-specific display drivers and DirectX technology However, rather than invent an entirely new set of controls and classes for client-side development, Silverlight uses a subset of the WPF model. If you' ve had any experience with WPF, you'll be surprised to see how closely Silverlight resembles its big brother. Here are a few common details ■| NTRODUCTION To define a Silverlight user interface(the collection of elements that makes up a Silverlight content region), you use XAML markup, just as you do with WPF. You can even map data to your display using the same data-binding syntax Silverlight borrows many of the same basic controls from WPF, along with the same styling system(for standardizing and reusing formatting), and a similar templating mechanism(for changing the appearance of standard controls) To draw 2D graphics in Silverlight, you use shapes, paths, transforms, geometries and brushes, all of which closely match their WPF equivalents Silverlight provides a declarative animation model that's based on storyboards, and works in the same way as wPF's animation system To show video or play audio files, you use the MediaElement class, as you do in WPF Note WPF is not completely cut off from the easy deployment world of the Web. WPF allows developers to create browser-hosted applications called XBAPS(XAML Browser Applications). These applications are downloaded seamlessly, cached locally, and run directly inside the browser window, all without security prompts. However although XBAPs run in Internet Explorer and Firefox, they are still a Windows-only technology unlike silverlight le Evolution of Silverlight Silverlight 1 was a relatively modest technology. It included 2d drawing features and media playback support. However, it didnt include the ClR engine or support for. NET languages, so developers were forced to code in JavaScript. Silverlight 2 was a dramatic change. It added the Clr, a subset of. NET Framework classes, and a user interface model based on WPF. As a result, Silverlight 2 was one of the most hotly anticipated releases in Microsofts history The versions of Silverlight since havent been as ambitious. Silverligh 5 keeps the same development performance enhancements. They highlights include. carefully selected group of features and model that was established in Silverlight 2, but adds a Performance improvements: Silverlight 5 starts faster, supports 64-bit browsers, and provides cleaner, crisper text rendering at small sizes Vector printing Silverlight improves its printing model to use vector printing, when possible (namely, if the print driver supports PostScript). The result is faster printing with less memory overhead( Chapter 9) Hardware-accelerated 3D graphics: Silverlight ports over a portion of the Microsoft XNA framework used for building Xbox games. With it comes a powerful but very low-level interface for rendering 3D scenes. Best of all, the video card does all the work, ensuring blistering performance( Chapter 13 XXXV


关注 私信 TA的资源