Published:
26 Oct 2009
|
Abstract
In this article, Scott provides a detailed overview of the new features of Windows Presentation Foundation (WPF) 4.0, particularly in the areas of Controls, XAML, Text, Graphics, Windows 7 integration (multitouch, taskbar integration, etc), Core Fundamentals, and Deployment. You will also learn the usage of the MultiTouch features included with Windows 7 in WPF applications. Scott also examines the data binding support, Visual State Manager, HTML-XBAP Script Interop, UIAutomation Virtualization and SynchronizedInput Pattern including a side-by-side comparison of the enhancements in client profile in .NET 4.0 as compared to .NET 3.5. Scott finishes the article with a reference regarding Full Trust XBAP Deployment. |
|
by Scott Guthrie
Feedback
|
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days):
66426/
115
|
|
|
Introduction |
Republished with Permission - Original Article
[In addition to blogging, I am now using Twitter for quick
updates and to share links. You can follow me on Twitter at: twitter.com/scottgu
(@scottgu is my twitter name)]
This is the eleventh in a series of blog posts I’m doing on the upcoming VS 2010
and .NET 4 release. Today’s post covers WPF 4.
|
WPF 4 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.
I will do a separate post soon that covers some of the major
advances coming with VS 2010’s WPF and Silverlight Designer – which also
includes a ton of improvements.
|
Controls |
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.
Figure 1
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.
|
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.
Figure 2
The WPF Ribbon will be fully extensible to meet changing
guidelines for future releases. A CTP with a limited feature set is available
today here
|
GRAPHICS |
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.
Figure 3
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.
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.
LayoutRounding
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.
Figure 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.
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.
|
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:
Figure 5
WPF’s new text stack also now supports explicitly selecting
aliased, grayscale, or ClearType rendering modes:
Figure 6
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.
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.
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.
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:
Figure 7
Figure 8
|
WINDOWS 7 LIGHT UP |
Windows 7 Multitouch 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:
Multi-touch Manipulation, Inertia (Pan, Zoom, Rotate) events
on UIElement
Raw multi-touch events (Up, Move, Down) on UIElement,
UIElement3D and ContentElement
Multiple capture supporting multiple active controls
ScrollViewer enhancement to support multi-touch panning
Touch device extensibility
Future Surface SDK compatibility
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.
Figure 9
WPF 4 integrates Windows 7 Jump List functionality,
including:
•Tasks
•Items
•Recent and Frequent Lists integration
•Custom Categories
Windows 7 Taskbar integration, including:
•Progress bar
•Overlay Icon
•Thumbnail buttons with commanding support
•Description Text DWM Thumbnail clipping
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.
Figure 10
Icon Overlays
Icon overlays allow an application to
communicate certain notifications and status to the user through its taskbar
button by display of small overlays which appear at the lower-right corner of
the button.
Progress Bars
A taskbar button can be used to display simple progress
information to the user without that user having to switch to the application
window itself. Progress bars can be used to track file copies, downloads,
installations, media burning, or any other operation that will take a period of
time.
Thumbnail Toolbars
Thumbnail Toolbars provide access to the key commands for an
application without the user having to restore or activate the window. This
feature enables application authors to embed an active toolbar control in a
window's thumbnail preview. The application can show, enable, disable, or hide
buttons from the thumbnail toolbar as required by its current state:
Figure 11
|
WPF FUNDAMENTALS |
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.
|
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.
|
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.
Figure 12
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.
|
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.
|
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.
|
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.
|
CLIENT DEPLOYMENT |
.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:
Figure 13
The same prerequisite dialog from above appears when you
create “Setup and Deployment” projects (under “Add New Project”/“Other Project
Types”). The NET4 Client Profile prerequisite entry is checked by default in
this case.
|
Enhancements in NET4 Client Profile vs. NET 3.5 SP1 Client
Profile |
Although the concept of a Client Profile is not new and was introduced in .NET Framework 3.5 SP1, the .NET Framework 4
Client Profile contains several important improvements:
|
.NET Framework 4 Client Profile (NEW)
|
.NET Framework 3.5 SP1 Client Profile
|
Supported OS
|
Supported on all platforms and OSs that are
supported by the .NET Framework (excluding IA64 and the Server Core role in
W2K8)
|
Supported only on Windows XP 32-bit machines that did not
have any .NET Framework version installed.
(Client Profile setup silently installs the full 3.5 SP1
Framework otherwise)
|
Redistributable
|
Supports redistributable as well as web download
|
Supports web download only
|
Add Remove Programs entries
|
The full Framework comprises the Client Profile and
another part called “Extended”. Thus it has two entries in the Add/Remove
Programs dialog (or Programs and Features window).
If you installed the Full Framework, you can switch to the
Client Profile by simply removing “Extended” from Add/Remove Programs.
|
Single entry in Add Remove Programs
|
Visual Studio
|
Improved support for Client Profile targeting in Visual
Studio 2010.
By default many Visual Studio 2010 Beta2 Client project
target the NET4 Client Profile.
|
Single checkbox in Visual Studio 2008 Service Pack 1 “Application”
Project properties for .NET Framework 3.5 projects. Client Profile support
unavailable in out-of-the-box VS 2008.
|
Features
|
Includes new .NET 4 features (such as Managed Extensibility Framework (MEF),
C#
4 Dynamic Keyword, etc) as well as features previously included in NET
3.5 SP1 Full (Speech, WPF Spell Check, etc)
|
Subset of features in .NET 3.5 SP1 Full
|
Because .NET 4.0 is a side-by-side release from previous
releases of the .NET Framework, installation of the .NET 4.0 Framework does not
require that prior versions of .NET on the machine need to be
serviced/patched. This means that the .NET 4.0 Client Profile installs
much faster on a machine than the .NET 3.5 SP1 Client Profile.
|
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.
|
Summary |
|
Resources |
|
|
|
|
User Comments
Title:
WPF
Name:
patel jay A
Date:
2010-08-03 5:28:27 AM
Comment:
good
|
|
|
|