Andy's profileAndyPhotosBlogGuestbookMore ![]() | Help |
Andy |
|||||
|
January 18 WPF in .NET 4.0
1. Improvements WPF (Windows Presentation Foundation) is one of the core components of the .NET Framework, and enables developers to build rich, differentiated Windows client applications. WPF 4 includes major productivity, performance and capability improvements – in particular in the areas of Controls, XAML, Text, Graphics, Windows 7 integration (multitouch, taskbar integration, etc), Core Fundamentals, and Deployment. This is the first of several posts I’ll do over the coming months about some of the improvements and new features.
2. Controls 2.1 Controls for building rich clients WPF 4 adds a variety of new controls that make building rich line-of-business applications for the client easier and faster. The new, richer control set includes LOB essentials such as DataGrid, DatePicker, and Calendar controls. These new controls are 99% API- and behaviorally-compatible with their Silverlight counterparts, enabling developers to create a consistent experience across the client and web while optimizing workflow by reusing code between Silverlight and WPF implementations. 2.2 Bag O’Tricks is back We are also releasing an out-of-band collection of eight controls called the WPF Bag O’ Tricks download. It includes the following controls: AnimatingTilePanel, ColorPicker, InfoTextBox, ListPager, NumericUpDown, Reveal, TransitionsPresenter, TreeMapPanel. 2.3 Windows 7 & Office ribbon control A new WPF Ribbon Control will be available for download shortly after the release of WPF 4. It features skins for Windows 7 and Office, as well as all the standard Ribbon features that end-users are familiar with, including tabs and groups, dynamic resizing, quick access toolbar, application menu, contextual tabs, key tips, and more. 3 Graphics 3.1 Cached composition Massive performance wins are possible with the new Cached Composition feature in WPF 4, which allows applications to cache arbitrary content including live and fully-interactive controls, vector geometry, etc. as bitmaps which persist in video memory. Once cached, these elements can be arbitrarily transformed, animated, manipulated, and can have Effects applied, all without having to re-render the cached element. This spares both the CPU and the GPU the cost of re-rendering content, and instead allows the GPU to render straight from the cache. The cache(s) understand dirty regions, so a blinking cursor in a cached textblock, for example, will only need to re-render the cursor between frames. There’s even a new Brush which specifically uses these intelligent caches – effectively a VisualBrush with vastly better performance. 3.2 Pixel shader 3 support WPF 4 builds on top of the very popular ShaderEffect support first introduced in WPF 3.5 SP1 by allowing applications to now write Effects using Pixel Shader version 3.0. The PS 3.0 shader model is dramatically more sophisticated than PS 2.0, allowing for even more compelling Effects on supported hardware. 3.3 Layout rounding WPF 4 adopts the UseLayoutRounding property, originally introduced in Silverlight 2. WPF’s layout engine frequently calculates sub-pixel positioning coordinates. This can lead to rendering artifacts as elements positioned on sub-pixel boundaries are anti-aliased over multiple physical pixels. UseLayoutRounding will force the layout engine to place elements on whole pixel boundaries, thus removing most of the rendering artifacts caused by this problem – which generates cleaner and crisper UI by default. 3.4 Animation easing function Discrete, linear, and spline animations were supported with previous versions of WPF. WPF 4 introduces a new concept of Easing Functions – which allows application authors to create fluid behavior using animations. This can be used in an infinite number of ways, such as creating a springy behavior, or adding anticipation to an animation. Easing Functions customize the manner in which animations progress from start to finish. The built-in easing functions provide a range of behaviors such as circular, exponential, elastic, and bouncy animation progress. The extensibility design also allows application authors to create custom easing functions to define the manner in which their animations progress. With this easy-to-use feature, designers can effortlessly create fluid, organic animations. 3.5 CleartypeHint The new CleartypeHint attached property allows application authors to enable higher-quality Cleartyped text rendering in many situations where it would have previously been disabled. Such situations include text in layered windows, text in VisualBrushes, DrawingBrushes, BitmapCacheBrushes, and anywhere else where the introduction of an intermediate render target would have previously resulted in grayscale text rendering. 4. Text stack New Text Rendering Stack The WPF text rendering stack has been completely replaced – a change that brings with it significant improvements to text rendering clarity, configurability, and support for international languages. The new text stack now supports display-optimized character layout, to produce text with comparable sharpness to Win32/GDI text. WPF’s new text stack also now supports explicitly selecting aliased, grayscale, or ClearType rendering modes. The new text stack allows optimizing text hinting and snapping for either animated or static text. Additionally, the new text stack now supports fonts with embedded bitmaps. This allows many East Asian fonts to render with the sharpness to which Win32 users have grown accustomed. 4.1 BindableRun Since the initial release of WPF, Run.Text has been a normal CLR property. This has meant that Run.Text lacks all the benefits of the WPF dependency property system, most notably the ability to be bound. In WPF 4, we have converted Run.Text to a dependency property allowing developers to use the first WPF supplied bindable Run. More details can be found here. 4.2 Custom Dictionaries WPF includes a spell checker which before WPF 4 only used the OS-provided dictionary for input validation. This has been a major issue for apps which target specific industries with specialized terminology, as those apps were plagued by misspelling notifications. WPF 4 has introduced an API to allow an application to add words to the dictionaries used by WPF for spell checking. More details can be found here. 4.3 Selection and Caret Brush In a push to allow rich customization of the look and feel of WPF apps, developers can also now change the brush used to paint WPF text selection and carets via two simple properties: SelectionBrush and CaretBrush. 5 Windows 7 Light up 5.1 Windows 7 Multiouch support With the introduction of multi-touch input and manipulation processing support, WPF 4 provides a great way to light up your client applications in Windows 7. Multiple finger input are exposed through existing and new input events in WPF 4, while new manipulation and inertia events are now available for developers to use. New features include:
5.2 Windows 7 shell integration WPF 4 also exposes several new and key Windows 7 Shell features to WPF developers. These Shell features enable a richer, integrated user experience. The new taskbar is less cluttered and can convey more information at a glance. The Aero thumbnails support user commands. Jump lists provide access to contextual startup tasks and files available to the application. WPF 4 integrates Windows 7 Jump List functionality, including:
Windows 7 Taskbar integration, including:
In Windows 7, the taskbar has been redesigned to be less cluttered and to help users perform tasks with fewer clicks. WPF 4 provides integration with the Windows 7 taskbar in XAML, allowing applications to surface useful information to the user from the application's taskbar icon using icon overlays, progress bar, thumbnail toolbars, thumbnail description text, and thumbnail clipping. There is also a new TaskbarItemInfo class in WPF 4 that is exposed as a dependency property. It encompasses all the new taskbar features introduced in Windows 7. 6 WPF Fundamentals 6.1 New XAML/BAML Parser Engine WPF 4 has replaced its implementation of XamlReader.Load(), BAML loading, Control & DataTemplates functionality with a new engine built on top of the new System.Xaml.dll. As part of this effort, we’ve fixed many bugs and made many functionality improvements. Users of XamlReader.Load() can take advantage of several new language features in XAML2009 such as support for generic types. MarkupExtensions and TypeConverters can now get more services during object graph creation, enabling more scenarios, such as access to the Root object. Tools to analyze and manipulate XAML will also be much easier to create with many of the new low level APIs provided in System.Xaml.dll. 6.2 Data Binding Support for DLR Unlike CLR classes, the members of dynamic objects are defined at runtime. DynamicObject is a new abstract class in the .NET Framework 4 that allows developers to easily implement IDynamicMetaObjectProvider. With C#’s new DLR support with the ‘dynamic’ keyword, we are expecting some library implementations to switch to using DynamicObject and IDynamicMetaObjectProvider as a standard way to exposing runtime defined properties and members of objects. WPF 4 data binding support for IDynamicMetaObjectProvider will allow the use of natural property syntax to access dynamic properties. This feature extends the WPF data binding engine to map the existing property and indexer access data binding syntax to support access to dynamic members offered by IDynamicMetaObjectProvider. 6.3 Visual State Manager( VSM ) Another new feature supporting the WPF-Silverlight continuum is the VisualStateManager, which introduces a simple new way to apply visual states to controls. This mechanism provides a way to easily customize both the look and feel of a control by providing the means to map the control logic to its respective start and end visual states. VSM is very flexible in that it automatically generates the transition animations in between the respective states, so the control author spends less time writing code and more time on the visual states that are defined in a control template. That means VSM can give a control author the ability to easily interchange the look and feel of controls, and VSM gives the control author a way to easily interchange how a control visually responds to user interaction. This is fully supported with Expression Blend. 6.4 HTML_XBAP Script interop WPF 4 provides the means for direct communication between an XBAP and script in the host HTML page (where the XBAP is loaded in an HTML frame or IFRAME element). The XBAP can get deep access to the HTML DOM, including to any ActiveX controls embedded in the containing HTML page and including handling of DOM events. WPF exposes the main script object from the host frame. This is a dynamic object that represents the frame’s window object plus any custom script functions and global variables from script in the HTML page. From it, an application can invoke script functions directly or “dot into” the HTML DOM. The functionality is available in partial-trust XBAPs and under all supported versions of Internet Explorer and Firefox. 6.5 UIAutomation Virtualization WPF has introduced virtualized controls in past releases; however there was never a standardized way for an automation client to interact with a virtualized control. Two control patterns, ItemsContainerPattern and VirtualizedItemPattern, have been added in WPF 4 to support access and interact with virtualized elements. ItemsContainerPattern is used to access the virtualized controls & find virtualized items and VirtualizedItemPattern is used to realize virtualized items. 6.6 SynchronizedInput Pattern This is another UIA control pattern added in WPF 4. This pattern could be used by automation clients to track whether the given input event is routed to the correct element by WPF framework. This pattern has three associated automation events, viz. InputReachedTargetEvent, InputReachedOtherElementEvent and InputDiscardedEvent to indicate where the input is handled. 7 Client deployment 7.1 .Net Framework 4 client profile To improve deployment size, time and overall experience of the .NET Framework 4 deployment, there is now a more compact version of .NET that is a subset of the full .NET Framework 4 - called the .NET Framework 4 Client Profile. The current redistributable size of the .NET Framework 4 Client Profile is about 30MB. The full Microsoft .NET Framework 4 is a pure superset of the Client Profile. The goal of the .NET Framework 4 Client Profile is to improve and help streamline the deployment size, time, reliability and overall deployment experience for client applications. The Client Profile contains the functionality that most common desktop client applications (including Windows Forms and WPF applications) would need so it is anticipated that the majority of client application developers will target it instead of the Full .NET Framework 4. For that reason, most Visual Studio 2010 Beta 2 client project templates target the .NET Framework 4 Beta 2 Client Profile by default. Unlike the .NET Framework 3.5 SP1 Client Profile, an important enhancement in the NET Framework 4 Client Profile is its support on all platforms and OSs, including those supported by the Full Framework like Windows Vista, Windows XP, Windows Servers 2003 and 2008, Windows 7, all for both x86 and x64. You can view or change the version of the framework that you target by opening your project’s properties window, and then select the "Application" page. You can then change the “Target framework” drop-down to either the full .NET Framework or the .NET Client Profile. The project Publish property page also allows you to select the prerequisite needed for your ClickOnce deployment. In Beta2, VS2010 automatically selects the correct profile (Client Profile or Full) depending on your primary project target. 7.2 Full trust XBAP deployment Starting in WPF 4, the ClickOnce elevation prompt is also enabled for XAML Browser Applications (XBAPs) in Intranet and Trusted Zones, making it easier to deploy full-trust XBAPs. For XBAPs that require security permissions greater than the minimum code access security (CAS) permission grantset of the Intranet and Trusted Zones, the user will be able to click 'Run' on the ClickOnce elevation prompt when they navigate to the XBAP to allow the XBAP to run with the requested permissions. Features of Silverlight 3
1. HD Media Silverlight 3 now supports hardware graphics acceleration – enabling both video and graphics compositing to be offloaded onto a GPU. This can dramatically lower CPU usage on a computer, and enables HD video to be played on older low end machines. You can now deliver and play 1080p HD video experiences over the web. Silverlight 3 includes new media codec support for H.264 video, AAC audio and MPEG-4 content. This enables you to easily play and stream media encoded using these standards. Silverlight 3 also includes raw bitstream audio/video APIs that enable you to create additional codecs (in any .NET language) that support playing any other media format. Silverlight 3 also adds a variety of additional media features that enable better logging (for media analytics and ad monetization scenarios), provide the ability to disable screen-savers when playing long-form video content, and enable content protection. IIS Media Services is a free server product that complements Silverlight and provides the ability to efficiently stream media over HTTP. It enables both on-demand and live HD video to be delivered using “smooth streaming” - which is an adaptive streaming algorithm that can deliver video at bitrates optimized for a client’s network conditions and CPU capabilities. Check out this demo to see a good example of smooth streaming in action with Silverlight. The HD support within Silverlight, combined with the Smooth Streaming support of IIS Media Services, enables a dramatically better video experiences on the web. This past week alone, we’ve had multiple customers broadcast live HD events using Silverlight and smooth streaming (up to 3MBits) including: Wimbledon, the Tour de France, AVP Volleyball, and the Michael Jackson Memorial Service. 2. Immersive Grphics The new GPU acceleration capabilities of Silverlight 3 enable even richer and more immersive graphic experiences. Silverlight 3 also adds new perspective 3D support that can be used with graphic elements, videos and controls. Silverlight 3 also includes new bitmap and pixel APIs, as well as the ability to create and apply custom pixel shader effects (e.g. blur, dropshadow, swirl, etc) to any image, video element, or control. Easing support can also now be used to enable more textured motion within animations. 3. Out of Browser Support Silverlight 3 enables applications to run outside the browser and taken offline. Users can safely install web applications on their computers, and create persistent shortcuts to them on the desktop, start menu and taskbar (this is supported on both Windows and the Mac). New network detection support within Silverlight enables developers to monitor the network status of a machine and switch between offline and online modes within their applications. Silverlight 3 also includes an automatic update mechanism for applications – so that clients who have installed applications are automatically updated when new application versions are deployed on the originating webserver. 4. Application Development Silverlight 3 includes a ton of new application development features. The Silverlight 3 runtime/SDK combined with the Silverlight Toolkit now includes ~100 UI controls that enable common scenarios (layout, data, charting, child windows, etc) while also providing full styling and template customization support. Silverlight 3 enables richer data binding features. Element to element binding support between controls is now enabled. Validation error template support has been added to controls (enabling better error message display). Hierarchical data binding is supported by the DataGrid. And a new DataForm control enables better master/detail scenarios. Silverlight 3 also now enables SaveFileDialog support. Silverlight 3 includes a new navigation framework that enables deep-linking and forward/back button integration within the browser. This also enables search engine optimization (SEO) support so that content within a Silverlight application can be indexed by search engines – including Google, Bing and Yahoo. Silverlight 3 also supports the ability to cache assemblies on the client, and re-use them across multiple applications (decreasing the download size and improving the startup time of applications). Silverlight 3 includes much better text rendering and font support. Text rendered using Silverlight 3 applications is much crisper and cleaner than previous releases, and applications now have access to local fonts. The Silverlight 3 styling system also now supports merged resource dictionaries, BasedOn style inheritance support, and the ability for styles to be reset any number of times. Silverlight 3 also adds richer accessibility support, and is the first browser plug-in to provide access to all system colors, allowing partially-sighted people to make changes such as high contrast color schemes for ease of readability using familiar operating system controls. Silverlight 3 includes richer networking support. WCF error faults are now supported across the network. Server-side push duplex support is now easier to setup. Binary XML serialization of payloads is now supported. The new .NET RIA Services framework (which now has a go-live license) can be used to easily build multi-tier data applications that span the client and server. .NET RIA Services enables you to write validation code once and have it applied on both the client and middle-tier layers of your applications.
BTW: all the contents above comes from "ScottGu’s Blog”. WPF and SilverLight comparison part IVSilverlight specific functionality 1. Web Functionality 1.1 Browser Interop A Silverlight application does not necessarily need to consume its entire hosted web page, and may exist as a smaller region within a rich HTML page. In the case where the Silverlight applet is a portion of a larger web page, it may become necessary for the applet to communicate with the page itself. 1.2 Media Silverlight supports rich media services delivered over the web. The Silverlight client supports several methods of receiving streaming media over the HTTP protocol. 1.3 Traditional streaming Silverlight can play media streamed to the client using a technique that sends data to the client at the bit rate of the encoded media, and only sends enough to fill the client buffer. Silverlight’s default buffer length is 5 seconds. This methodology reduces bandwidth consumption since if the client is paused or cancelled, the only wasted bandwidth would be from the data stored in the buffer. 1.4 Progressive download Silverlight also implements the progressive download delivery method. Unlike smooth-streaming, the progressive download method streams the entire media file to the client. The client, however, can begin playing the media without it being completely downloaded. If the client pauses or cancels the player, the server continues to transmit the entire media file to the browser’s cache. 1.5 Smooth streaming Silverlight also supports a relative new adaptive streaming technology dubbed Smooth Streaming. Smooth Streaming is a hybrid technology, combining traditional streaming with progressive downloading; transmitting a series of small progressive downloads instead of a single large one. The Smooth Streaming technology is adaptive in that the client can request pieces of data of various sizes to optimize bandwidth consumption. In addition, the source media can be stored at different bit rates, and the client can seamlessly choose the best bit rate to use based on any number of factors, including network conditions and CPU usage. 1.6 Timeline markers A timeline marker is metadata stored directly within the media file to provide the capability to skip to specific positions or provide cues for scripting. Within Silverlight, these timeline markers generate a MarkerReached event within the MediaElement class. The event can be handled in code to provide any number of enriching experiences, such as media pop-ups. 1.7 Deep zoom Deep Zoom is a technology for viewing extremely high resolution images through Silverlight. The technology allows for quicker downloads of a large image by only displaying the portion being viewed. Deep Zoom also pre-processes an image into many separate resolution images to allow for speedier zooming and panning. 2 Code reuse strategies Sharing code between Silverlight and WPF can be a daunting task, as seen by the myriad differences between the two platforms. However, with careful planning, developers can share a significant amount of code between the two technologies. Microsoft is committed to bringing Silverlight and WPF closer together with each release. 2.1 User controls Custom user controls are one way to begin sharing code between WPF and Silverlight applications. Controls built completely in code would work the most seamlessly, provided that any specific Silverlight or WPF code is cordoned off with the use of compiler directives. There may be some issues in sharing XAML directly due to differences in the xmlns declarations. 2.2 Partial classes Version 2.0 of the .Net Framework implemented a feature known as partial classes. Essentially, a partial class tells the .Net compiler that additional implementation exists in a separate file; thus, allowing a developer to organize their classes across multiple files. 2.3 Extension methods New to version 3.0 of the .Net Framework are extension methods. Extension methods are static methods contained within a static class and have a particular method signature. These methods essentially, add functionality to existing value types or classes. 2.4 Compiler directives Compiler directives are embedded commands to instruct the compiler how to compile a certain section of code, also known as conditional compilation. At compile-time the conditional statements are evaluated and the proper code fragments are incorporated into the assembly. 1: #if SILVERLIGHT 2: // Perform Silverlight-only tasks. 3: #else 4: // Perform WPF-only tasks. 5: #endif 2.5 Linked files Silverlight projects implement a separate CLR than WPF projects. Therefore, it is not possible to share sub-projects, such as a shared library, across applications. One solution to reuse code in both platforms would be to link files through Visual Studio into new sub-projects for each 2.5 Coding scenarios There are several scenarios when coding for both platforms that require some forethought in order to reduce code redundancy. While this whitepaper outlined many of the differences and similarities between the two platforms, the following section details some of the more common development areas where the differences between the two platforms become problematic when trying to share code. 2.5.1 Element to element binding WPF supports element-to-element binding to facilitate designing the UI when controls rely on values from other controls. However, since Silverlight 2 does not support element-to-element binding, developers should concentrate on creating an intermediate class to store the values 2.5.2 Multi data binding Since Silverlight does not support multi-data binding, developers needing cross-platform support should build their application to the lowest common denominator. Building a separate class to aggregate the multiple values would mimic the WPF functionality. Both Silverlight and WPF can react to classes supporting INotifyPropertyChanged and parse the multiple values correctly in a ValueConverter. 2.5.3 Triggers /Visual state manager Adding UI effects to controls can be one of the most troublesome areas to reduce code redundancy. WPF supports various triggers to obtain visual effects while Silverlight implements a Visual State Manager. WPF only supports the Visual State Manager in the WPF Toolkit, and at the time of this writing, is only in beta. Using the VSM would yield the most mode reuse between the two platforms, assuming the WPF Toolkit has been installed. 2.5.4 Fonts Silverlight has the capability of obtaining fonts in many different ways: from embedding as a resource within the assembly, or externally loaded via an asynchronous web request. WPF can use any font resource available on the Windows system without these extra steps. Since adding fonts to Silverlight applications can increase the size of the application’s footprint, it is recommended to judiciously embed fonts and instead download them asynchronously when needed. 3.0 Summary WPF and Silverlight provide a new paradigm for application development using the same core technology of declarative XAML and the well-known code-behind model for procedural code. Silverlight, generally considered to be a subset of WPF, has been moving closer in implementation with each successive release. However, since Silverlight runs as an application within the plug-in model of a browser, it will always be hampered in some ways that will require innovative thinking to work around: whether in code or in application design. Future releases of both Silverlight and WPF have been making advancements to close the distance in the differences between the two platforms. January 15 WPF and SilverLight comparison part III
1. .NET Framework Silverlight contains a subset of the .Net framework, called CoreCLR, and there are noticeable differences in implementation of even the most mundane functionality. Producing an exhaustive list of framework differences would be a daunting task. Silverlight only supports half the overloaded methods as WPF. These types of differences can be found throughout the entire .Net Framework. 1.1 Collections Looking at the System.Collections and System.Collections.Generic namespaces, several differences between the implementations of both platforms become apparent. Typically, this should not be a problem since most of these collections are available in a generic form. However, use of these classes can be problematic when porting code from WPF to Silverlight. Unfortunately, Silverlight doesn’t support the highly efficient HashSet<T>; other data structures would need to be used as Silverlight doesn’t support the HashTable collection either. 1.2 Cryptography Like most aspects of Silverlight, cryptography support is a subset of the WPF implementation. Comparing the classes in System.Security.Cryptography namespaces in both platforms would not be especially helpful (there are 107 classes in the namespace for WPF, and only 20 for Silverlight). Silverlight supports four hashing algorithms: SHA1, SHA1Managed, SHA256, and SHA256Managed. WPF supports all the .Net hashing algorithms. 1.3 Threading 1.3.1 Interprocess synchronization WPF supports several methods for synchronizing threads between processes; such as the Monitor, Mutex or Semaphore classes. Silverlight, however, only supports the Monitor class for synchronization. 1.3.2 Locking WPF implements support for the ReaderWriteLock class, enabling locks on resources to support single writers and multiple readers. Silverlight supports locking through the Monitor class, which grants locks to an object for a single thread. The Monitor class can ensure that no other thread is allowed to access a code section except by that of the lock owner. Though a bit coarser than the locks available to WPF, the Monitor should prove to be sufficient for most multi-threaded needs in Silverlight.
2 WPF Specific Functionality WPF applications are primarily desktop applications running within the confines of a Windows operating system. As such, WPF applications do not have the restrictions imposed on Silverlight which runs in a tightly controlled sandbox within the confines of a web browser. Desktop functionality 2.1 Printing Unlike printing in the WinForms era, printing in WPF is relatively straight-forward. Any visual element can be printed, but the most likely scenario would be printing an entire Window. This basic printing has limitations: if the size of the visual is larger than an actual page, the content will get clipped. For more complex printing needs, such as multiple page printing, WPF offers the PrintDocument method. Instead of printing a Visual element, the PrintDocument accepts a DocumentPaginator object. The DocumentPaginator is an abstract class, so developers will have to define a class to perform the more complex functionality of multiple-page printing. 2.2 XPS documents XML Paper Specification (XPS) documents maintain a consistent appearance across all display mediums. WPF has full support for creating, viewing and printing XPS documents through the XpsDocumentWriter and XpsViewer classes in the System.Windows.Xps namespace. There are two types of documents, FlowDocument and FixedDocument. FlowDocuments can adjust its content to make use of the space within the page. 2.3 Speech WPF supports the speech APIs found in the System.Speech namespace, which in turn, are wrappers around the Microsoft SAPI framework, a Win32 library. However, the speech API is not actually WPF technology: no dependency properties, routed events, or other aspects that make WPF what it is. In fact, there is no XAML syntax for speech; instead speech relies on a different XML dialect called Speech Synthesis Markup Language (SSML). There are two aspects to the speech APIs: synthesis (speaking text) and recognition (listening to commands). The System.Speech namespace provides classes for both concepts, but recognition requires a speech recognition engine to be installed. Fortunately, Windows Vista has one by default (as well as Office XP or later). 2.4 InterOp Interoperability in WPF generally refers to interacting with previous technology such as Win32 applications, COM+, and ActiveX controls. 2.4.1 WindowsFormsHost The WindowsFormsHost control allows a developer to embed a WinForms control directly into a WPF application with little work. However, the WindowsFormsHost control cannot overlap or be overlapped by any WPF content. Each region in an application can only be controlled by one display technology. 2.4.2 ElementHost ElementHost is the Windows Forms equivalent of WindowsFormsHost, and allows embedding of WPF elements within a WinForms application. Of course, in WinForms, the work must be done in code instead of declarative XAML. 2.4.3 ActiveX Controls Embedding an ActiveX control in a WPF application uses the same methodology as embedding a Windows Forms control; that is, via the WindowsFormsHost element. However, the reverse, exposing a WPF control as an ActiveX control is not currently supported. 2.4.4 Advanced Interop More complex interoperability may be performed in WPF through the knowledge of window handles (HWNDs). While most of WPF does not implement any method for interacting with HWNDs, the HwndHost, a subclass of FrameworkElement, class can host any object exposing an HWND. In addition, WPF defines an HwndSource to expose any visual element as a HWND for consumption in a Win32 application. 2.4.5 XAML WPF supports some additional XAML elements and attributes than Silverlight. Styles are one example where WPF adds additional functionality. Note, Microsoft is working to implement more and more of WPF within the Silverlight platform. 2.4.6 Styles Styles in WPF are analogous to HTML’s cascading style sheets, in that they allow changing the appearance of any visual element from a single location; essentially abstracting the look of the control from its functionality. While both WPF and Silverlight can use styles, WPF implements additional functionality with regard to styles. 2.5 User interface 2.5.1 3D graphics WPF supports hardware accelerated 3D functionality within the WPF graphics system. All 3D content is viewed through a Viewport3D container, and can be completely declared from within XAML. WPF supports many 3D features including cameras, models, meshes, materials, lights, transformations and animation. 2.5.2 Themes Themes are a set of visual styles and control templates available to WPF applications and are not necessarily application-specific. WPF installs several OS-specific themes such as “Windows Classic,” “Luna”, and “Aero” to name a few. In addition, additional themes may be found for free and for sale on the internet. In practicality, themes are defined as resource dictionaries containing implicit styles and control templates for as many elements as necessary to define the theme. In most cases, virtually every visual control would be styled in the theme. 2.5.3 Sknis Skins are almost identical to themes, except that skins are geared to a specific application while themes are system oriented. Different applications can share system-wide themes, while an individual application may support additional skins. 2.6 Image manipulation WPF implements common imaging capabilities found with the Microsoft GDI+ library, as well overcoming some of the short-comings of that aging library. WPF supports both managed and unmanaged image manipulation libraries. However, this document will focus on the managed library found within the Systme.Windows.Media and System.Windows.Media.Imaging namespaces. 2.6.1 WPF Image Formats WPF supports the following bitmap (raster) image types: 2.7 Page-based navigation Traditional client development centers on windows and forms and WPF has no issues working in that paradigm. However, the internet brought the web page, and navigational-based web applications. WPF attempts to bridge the divide by bringing the page-based navigation metaphor to the desktop. 2.8 Imput Gestures While the term gestures may suggest some fancy high-tech method for analyzing mouse movements, the reality is much simpler. Input gestures are a facility for defining a sequence of key-strokes, such as Alt-C or Ctrl-Alt-F2 or mouse button clicks such as Alt-Left Click. 3 General functionality 3.1 Freezable objects A freezable object in WPF is an object deriving from the Freezable base class. It is special in that when frozen, the object can no longer be modified. Once frozen, the object can then be shared across threads and processes; non-frozen objects cannot be shared in this manner. Once frozen, a freezable object cannot be unfrozen; however, it can be cloned. In addition, not all freezable objects can be frozen and therefore the base class exposes a CanFreeze property. 3.2 Data providers WPF implements a data provider model for data binding and ships with two concrete data provider classes: ObjectDataProvider and XmlDataProvider. In addition, it is possible to create custom data providers by deriving from System.Data.DataSourceProvider. 3.3 Validation WPF provides a framework for adding validation rules to data bindings. The Binding class contains a collection of ValidationRules in which one or more objects deriving from ValidationRule can be loaded. Each rule is checked in turn, therefore, all the rules must pass or the validation fails. Additionally, the validation engine can also be configured to handle exceptions that may arise in the data source itself by using the ExceptionValidationRule. 3.4 Dynamic resources Dynamic resources differ from static resources in that the framework will evaluate the dynamic resource every time it is used, whereas a static resource is evaluated once and cached. Dynamic resources syntax is identical to static resources; other than specifying the DynamicResource markup extension instead of the StaticResource extension. 3.5 Code access security WPF supports the .Net Framework’s implementation of code access security (CAS). This security mechanism limits access to system resources and functions. A full discussion of code access security is beyond the scope of this paper. In essence, CAS defines permissions and permission groups that represent a right to access particular system resources. Code can then request permissions in which it needs to run, what it would like to have, and what permissions it should never be granted. All WPF applications, except web browser applications (WBAs), require FullTrust permissions in order to run. Web browser applications, however, are run with partial trust; typically using one of the zone-based security sandboxes defined within Internet Explorer (such as the Internet or Intranet zones). WPF and SilverLight comparison part II
1. General 1) Routed Events There are three types of routed events: direct, bubbling and tunneling. Direct events are those events that are only handled by the element creating the event. Bubbling events are those events that travel upward through the visual tree and can be handled by any parent of the source element. Finally, tunneling events are those events that travel downward through the visual tree and can be handled by any child of the source element. 2) Data binding Data-binding is WPF’s and Silverlight’s mechanism of associating data to controls. Changes to the source data are propagated to the associated controls according to the binding rules set on them. Data can be bound to just about any property on any UI element. 2.1) Binding modes Silverlight does not support the One-Way To Source binding mode. 2.2) UpdateSourceTrigger Silverlight does not support Explicit data-binding. In order to force a data-binding refresh, the property changed event must be fired in the data source, or the UI element must be forced to lose focus. 2.3) Multi binding Data binding maps a single data element to a single property of a UI element. MultiBinding allows binding multiple data elements to a single property of a UI element. MultiBinding, unlike regular binding, requires the use of a ValueConverter, or more specifically, a MultiValueConverter. It would be remiss not to mention a simpler solution to this problem in WPF. With Service Pack 1 of WPF 3.5, the StringFormat property has been added to bindings. The above XAML could be rewritten, without the use of a MultiValueConverter, as: 1: <TextBlock> 2: <TextBlock.Text>3: <MultiBinding StringFormat="{}{0} {1}"> 4: <Binding Source="{StaticResource Person}" Path="FirstName" /> 5: <Binding Source="{StaticResource Person}" Path="LastName" /> 6: </MultiBinding> 7: </TextBlock.Text> 8: </TextBlock>WPF supports multiple data-binding while Silverlight only allows binding to single value. However, a viable work-around in Silverlight would be to create a custom class to aggregate the multiple data elements into a single property and either parse them in the Value Converter or use the composite value directly. 2.4) Element binding WPF supports binding to other elements within the visual tree. 2.5) Data providers While the source object can be any .Net object, WPF provides some specialized data providers to enhancing the binding experience. The XmlDataProvider and the ObjectDataProvider are two such data providers. Silverlight, on the other hand, does not provide an implementation of the ObjectDataProvider. 2. Networking 2.1 Communications Silverlight does not have the capability of making a synchronous networking request due to the potential of blocking the main UI thread. Silverlight can only make asynchronous network calls. In addition to HTTP communications, Silverlight also can communicate to network resources via socket programming. Socket development provides interfaces for developers who require a more tightly controlled access to the network. 2.2 Http communications Support for HTTP communication opens the door to several options within Silverlight; web services, WCF Services, and REST. Note that Silverlight is still bound to the supported bindings listed below in the BINDINGS section. 2.3 SOAP Silverlight supports SOAP 1.1 over HTTP, and does not support other versions of SOAP, or other web services not compliant with WS-I Basic Profile 1.0. WPF can support all SOAP versions and multiple encoding types. 2.4 Fault handling Silverlight cannot currently natively handle SOAP Fault Exceptions due to web browser limitations. When a fault does occur, an exception is thrown, but does not specify any detail about the fault. In essence, Silverlight can determine a fault happened, but not why it happened. 2.5 Concurrent connections Silverlight is bound to the browsers networking stack and is limited to its concurrent connection settings. The most restrictive of these limits is two concurrent connections, but is dependent on the system’s maximum network connections. This setting can be changed in the registry under the following key: 2.6 Bindings Network bindings define the methodology an application uses to connect to network resources. 3. Local isolated storage There are some significant changes in the implementation of local isolated storage between Silverlight and WPF. There are two classes shared between WPF and Silverlight involving isolated storage: IsolatedStorageFile and IsolatedStorageFileStream. Both classes have significantly different implementations, and in addition, the Silverlight implementation marks most of the methods as SecuritySafeCritical or SecurityCritical. Silverlight also implements the concept of a quota, prohibiting Silverlight applications from consuming excessive amounts of physical disk space. By default, a Silverlight application is allowed to consume up to 1 MB of storage. Applications may increase their quota after receiving approval from the user. 4. Resource dictionaries Both Silverlight and WPF support resource dictionaries. Resource dictionaries can exist in multiple places throughout the application; from the application itself to individual controls. 4.1 Merged dictionaries WPF supports external resource files and the ability to merge them into one cohesive resource dictionary. Silverlight, unfortunately, does not currently support merged resource dictionaries. However, it is possible to craft a similar solution to dynamically populate the application resource collection at runtime. 4.2 Other differences In WPF, the FrameworkTemplate base class used for templating, contains a Resources collection property. Silverlight’s implementation of the FrameworkTemplate class does not have a Resources property. 5. Custom dependency properties 5.1 Coerce- value callback Silverlight does not support WPF’s implementation of coerce-value callbacks and DependencyObject.CoerceValue. However, since Silverlight supports property-changed callbacks, most of the missing implementation can be added. 5.2 Read-only properties Silverlight does not support read-only dependency properties. Unfortunately, there is no fool-proof method for working around this limitation since any external code can call set the property through the use of the SetValue method. 5.3 Property metadata Overriding metadata is not supported in Silverlight; a dependency property’s metadata is set as initially registered to the owner type and cannot change. 5.4 AddOwner The AddOwner mechanism is particularly useful in WPF when attempting to change the PropertyMetadata of a dependency property defined in an existing class. AddOwner allows the re-registering of a dependency property to a new owner. Silverlight does not support the AddOwner method on the DependencyObject class. 6. Commanding Commanding is an input mechanism introduced in WPF to provide a separation between UI elements and the actions taken. Silverlight does not support the concept of commanding as defined in WPF, it only supports the ICommand interface. Some third-party projects, both open source and off-the-shelf libraries and used the interface to provide rudimentary commanding to Silverlight. |
||||
|
|