Lập trình .net 4.0 và visual studio 2010 part 61 pptx

8 283 0
Lập trình .net 4.0 và visual studio 2010 part 61 pptx

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

Thông tin tài liệu

CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 403 Performance Microsoft has been hard at work tweaking Silverlight 3.0’s performance. Let’s look at what has changed. Binary XML Support Silverlight 3.0 has support for Binary XML, allowing you to communicate with WCF binary XML endpoints. Binary XML format is much smaller than regular XML and results in less data being transferred over the network and ultimately better performance for your applications. Enhanced Deep Zoom performance DeepZoom is now much quicker than ever before (not that it was slow before). Improved XAP Compression XAP files are now compressed more efficiently, and Microsoft says you should see a 10–30 percent decrease in size compared with previous versions. Silverlight.js The JavaScript file Silverlight.js in Silverlight 3.0 is compressed and is now just 7k in size (previous versions were 57k). To obtain the uncompressed version, go to http://code.msdn.microsoft.com/silverlightjs/. Assembly Caching Silverlight applications can be reduced in size by utilizing a new feature called assembly caching . When assembly caching is turned on, core .NET assemblies used by your app will not be included in the Silverlight XAP file that is downloaded by the client. If clients don’t have these assemblies on their machine, then they will be downloaded directly from Microsoft. Enabling assembly caching is very easy: 1. Open the Properties dialog of the Silverlight project 2. Check the Reduce XAP size by using application library caching check box (see Figure 15-32). 3. Recompile your Silverlight application, and you're done.  CAUTION Cached assemblies will be cleared if the browser cache is cleared. CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 404 Figure 15-32. Enabling cached assemblies GPU Acceleration Silverlight 3.0 allows you to shift resource-intensive tasks such as clipping and transformations to the GPU. GPU acceleration must first be enabled at the application level. 1. Open Chapter15.OfflineTestPage.aspx and add the following parameter: <param name="EnableGPUAcceleration" value="true" /> 2. Add the CacheMode property to controls that you want to implement caching and set it to BitmapCache: <Image Source="sydney.jpg" CacheMode="BitmapCache" ></Image> CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 405  NOTE Some effects such as pixel shaders, render transforms, and plane projections do not benefit from GPU acceleration because the calculations for them are always carried out on the CPU.  TIP Silverlight can highlight elements on your page that are utilizing caching if you set the EnableCacheVisualization property in app.config to true. When this setting is enabled, Silverlight will use the cache to tint elements a light red color so you can see what's cached. Miscellaneous Enhancements Silverlight 3.0 has a number of other minor tweaks and enhancements. Controls There are more than 60 new controls in Silverlight 3.0 (many originally part of the Silverlight Toolkit) and to go through them would require several chapters. However, I will tell you that Silverlight now contains charting, docking, auto-complete, time, accordion, and tree view controls. Listbox The Silverlight Listbox control now supports multiselection. TextBox Cursor Styling The TextBox caret can now be styled in WPF 4.0 and Silverlight 3.0 with the CaretBrush property. This code example changes the caret to a yellow color: <TextBox x:Name="txtValue" Width="400" CaretBrush="Yellow" Canvas.Top="50"> </TextBox> Accessibility Silverlight 3.0 is the first browser plug-in that allows you to utilize any color in the system palette. This can assist partially sighted people by allowing them to view controls in high-contrast schemes. Browser Zoom Support Silverlight 3.0 now supports browser zoom requests. CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 406 Slsvcutil.exe The Silverlight SDK contains a new command-line utility for generating proxy classes. This script demonstrates how to use this utility: slsvcutil.exe http://myservice.com/myendpoint.svc?WSDL. WCF RIA Services Not really a Silverlight 3.0 change, but I want to make you aware of a new framework called WCF RIA Services. Many Silverlight applications need to perform simple add, update, delete, and call functions, and it can be very tedious to write web service methods to fulfill these requirements.WCF RIA Services will meet these needs and many more; see http://code.msdn.microsoft.com/RiaServices. Blend 3/SketchFlow Although VS2010 contains excellent design time support for WPF and Silverlight, if you make many aesthetic changes or are a designer you are probably better off using Blend 3. Blend 3 also contains a great feature called SketchFlow that allows you to produce prototype applications (see Figure 15-33): Figure 15-33. Blend 3 and SketchFlow CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 407 Silverlight 4.0 At the time of writing the first beta of Silverlight 4.0 has just been released. (I don’t envy Silverlight authors; their books must have the shortest lifespan in the world.) I have summarized some of the important changes here: • Printing support (yay!) • MEF support • New controls: TextBox with hyperlink, masked TextBox, DataGrid with copy/paste functionality • Webcam and microphone support • Copy-and-paste functionality • Mouse wheel support • Google Chrome support • Performance optimizations • Multitouch support • For trusted applications, read/write to documents folders, run other desktop programs (e.g., Microsoft Office suite) • New interface for requesting more privileges for applications • Localization enhancements (right-to-left text and complex scripts) For more information, please refer to http://silverlight.net/getstarted/silverlight-4-beta/. Silverlight in the Real World Some developers consider Silverlight little more than a toy at present and argue that it is not suitable for serious line of business applications. Can Silverlight really be used to produce a line of business application? I talked to Rusty and Andy at SharpCloud about their experiences of developing a Silverlight application. Rusty Johnson and Andy Britcliffe, SharpCloud SharpCloud (http://www.sharpcloud.com) is currently developing a “project risk assessment application.” The application carries out complex calculations to determine the optimum order for carrying out projects. The application is built using Silverlight and WCF, and it runs on the Windows Azure (see Chapter 16). It is shown in Figure 15-34 and Figure 15-35. CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 408 Figure 15-34. SharpCloud’s Silverlight application Figure 15-35. SharpCloud’s Silverlight application CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 409 Rusty and Andy summarized their experiences here: • They developed a usable application from scratch in about four months (“startup” days, not 9–5!). • It is quite easy for .NET developers to get up to speed with Silverlight (although Andy did have a lot of Silverlight experience). Andy mentioned that some developers might struggle to understand the async event model. • Don’t load your entire application at once, but be prepared to use dynamic loading facilities (Andy recommended looking at PRISM and the following URL: http://www.sparklingclient.com/prism-silverlight/.) • Be prepared to do much work tweaking the performance of your application. • Utilize third-party components (graphing in particular) because Silverlight's current toolkit is lacking. • Some third-party Silverlight control vendors are not taking full advantage of Silverlight's capabilities and producing controls that run in Silverlight but work like an ASP.NET control. • Much of the layout work was hand-coded rather than using designer features. • Blend 3 seems slower than Blend 2, but contains some great features such as SketchFlow. Summary There are some fantastic new features in WPF 4.0 and Silverlight 3.0. And the release of Silverlight 4.0 is just around the corner. If you are beginning a new project should you create it using Silverlight or WPF? Pete Brown (Developer Community Program Manager for Windows Client) has the following to say on his blog: “In the future, it is very likely that both Silverlight and WPF will be a single technology with a single codebase. After all, Silverlight was originally known as WPF/E (E as in Everywhere), and in an amazing 180 degree reversal of our usual approach, we took an ugly codename and created a great product name (Silverlight) from it.” http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2009/12/01/The-Future- of-Client-App-Dev-_3A00_-WPF-and-Silverlight-Convergence.aspx Whatever happens (and it's likely this merge won’t happen overnight), it is clear that WPF and Silverlight have a very bright future ahead and are certainly technologies to invest io invest in. Further Reading • http://msdn.microsoft.com/en-us/library/bb613588(VS.100).aspx • http://blogs.msdn.com/llobo/ • http://blogs.windowsclient.net/rob_relyea/ CHAPTER 15  WPF 4.0 AND SILVERLIGHT 3.0 410 • http://weblogs.asp.net/scottgu/archive/2009/10/26/wpf-4-vs-2010-and-net-4- 0-series.aspx • http://community.irritatedvowel.com/blogs/pete_browns_blog/ • http://silverlight.net/getstarted/silverlight3/ • http://timheuer.com/blog/archive/2009/03/18/silverlight-3-whats-new-a- guide.aspx • http://blogs.windowsclient.net/rob_relyea/archive/2009/03/25/xaml-in-net-4- update.aspx . http://msdn.microsoft.com/en-us/library/bb613588(VS. 100 ).aspx • http://blogs.msdn.com/llobo/ • http://blogs.windowsclient .net/ rob_relyea/ CHAPTER 15  WPF 4. 0 AND SILVERLIGHT 3 .0 41 0 • http://weblogs.asp .net/ scottgu/archive/ 200 9/ 10/ 26/wpf -4- vs- 201 0-and -net- 4- 0- series.aspx. http://weblogs.asp .net/ scottgu/archive/ 200 9/ 10/ 26/wpf -4- vs- 201 0-and -net- 4- 0- series.aspx • http://community.irritatedvowel.com/blogs/pete_browns_blog/ • http://silverlight .net/ getstarted/silverlight3/. 15-33. Blend 3 and SketchFlow CHAPTER 15  WPF 4. 0 AND SILVERLIGHT 3 .0 40 7 Silverlight 4. 0 At the time of writing the first beta of Silverlight 4. 0 has just been released. (I don’t envy Silverlight

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

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan