Home > Store

WPF Control Development Unleashed: Building Advanced User Experiences

Register your product to gain access to bonus material or receive a coupon.

WPF Control Development Unleashed: Building Advanced User Experiences

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2010
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-33033-4
  • ISBN-13: 978-0-672-33033-9

WPF Control Development Unleashed

Building Advanced User Experiences

In this book, two leading Windows Presentation Foundation experts give developers everything they need to build next-generation WPF applications–software that is more robust, usable, and compelling.

Drawing on their close ties with Microsoft’s WPF development team, Pavan Podila and Kevin Hoffman give you a clear, robust, and practical understanding of WPF, its underpinnings, its overall architecture, and its design philosophy. Podila and Hoffman introduce never-before-published WPF design patterns and support them with robust, real-world code examples–all presented in full color, just as they appear in Visual Studio.

The authors begin by explaining how to “think in WPF,” and then introduce powerful new techniques for everything from handling 3D layouts to creating game-like physics effects. Along the way, they offer in-depth coverage of data binding, building interactivity, and control development: three of WPF’s most challenging concepts. You’ll learn how to choose the right WPF features for every programming challenge, and use those features far more creatively and effectively.

If you want to build truly outstanding WPF applications, this is the book that will get you there.

  • Master the patterns and techniques you need to build state-of-the-art WPF applications
  • Write more powerful and effective applications that reflect a deep understanding of WPF’s design philosophy
  • Learn how WPF has evolved, and take full advantage of its growing sophistication
  • Make the most of advanced declarative programming techniques
  • Leverage IScrollInfo, virtualization, control theming, and other complex features
  • Build more powerful interactivity into your WPF applications
  • Create more visual software with 3D elements, custom animations, and shader effects
  • Optimize WPF application performance in real-world environments
  • Master design patterns for organizing your controls more effectively

Category: .NET Programming / WPF

Covers: Windows Presentation Foundation

User Level: Intermediate—Advanced

Downloads

Downloads

Download the example files

Sample Content

Online Sample Chapter

WPF Control Development: The Diverse Visual Class Structure

Sample Pages

Download the sample pages (includes Chapter 2 and Index)

Table of Contents

About the Authors          xii

Dedications           xiii

We Want to Hear from You!        xv

Part I Thinking in WPF

1 The WPF Design Philosophy 1

Data and Behavior           2

Working with Data          3

Templates            3

Presenters            4

Binding and Converters         4

Layout            5

Styles            5

Working with Behaviors          6

The User Experience          8

The User Experience Benevolent Circle       9

A Note on Sample Source Code       9

Summary           10

2 The Diverse Visual Class Structure 11

Introducing the Visual Classes        11

The DispatcherObject Class        12

The DependencyObject Class        12

The Visual and DrawingVisual Classes       13

The FrameworkElement Class       15

The Shape Class          16

The Text Classes          18

The Control Class         19

The ContentControl Class         20

The ContentPresenter Class        20

The ItemsControl Class         21

The UserControl Class         22

The Panel Class          23

The Decorator Class          24

The Adorner Class         24

The Image Class          25

The Brushes          25

The DataTemplate, ControlTemplate, and ItemsPanelTemplate Classes        27

The Viewport3D Class         27

The MediaElement Class        28

The InkCanvas          28

Summary           29

3 Getting Started Writing Custom Controls 31

Overcoming the “Start from Scratch” Instinct     31

Using Data Transformations        32

Find the Behavior You Want, Then Extend     34

The Power of Attached Properties       35

Custom Control Creation Checklist      38

Thinking in Layers–The Art of Decomposition    39

Sample: Building a Circular Minute Timer      40

Enhancing and Extending the ProgressBar     40

Creating the Arc Shape         42

Working with the ControlTemplate      43

Summary           47

4 Building Custom Panels 49

Layout Defined          49

How Layout Works          51

Working with Visual Children        52

Creating a Custom Panel: The VanishingPointPanel     56

Building a Panel with Attached Properties: WeightedPanel    58

Using Transformations with Layout       63

Enter the LayoutTransform        66

Layout Events           66

Summary           68

5 Using Existing Controls 69

Customizing Existing Controls        70

Customizing Controls Using Properties      70

Customization Using Control Templates      70

Customization with Data Templates      71

Using a ControlTemplate and a DataTemplate     71

Customizing the ItemsControl        72

Customizing a ListBox          74

Customizing the ItemContainerStyle      74

Customizing the ItemTemplate and the ItemsPanelTemplate  77

Creating a Custom ScrollBar         78

Using Brushes to Create Advanced Visuals      82

Using the VisualTreeHelper and LogicalTreeHelper    82

Customization Sample–The Radar Screen      83

Moving Enemies in a ListBox        84

Concentric Circles and a Sweeping Cone      85

Summary           91

6 The Power of Attached Properties 93

Overview of Attached Properties        93

Building the UseHover Attached Property     95

Using Attached Properties as Extension Points     100

Data Templates          102

Property Abstraction         102

Layout Animations          102

Constraining Panels         102

Application Services         102

UI Helper Objects         103

Implementing Drag and Drop with Attached Properties   103

Summary            111

Part II Adding Complex Features

7 Advanced Scrolling 113

The Anatomy of a Scrollbar         113

The Magic of IScrollInfo         115

Responding to User-Requested Horizontal and Vertical Scrolling 116

Controlling the Bounds for the Track and Thumb    116

Managing the Location of the Thumb      116

Logical Scrolling         117

Building a Custom Panel with Custom Scrolling     117

Creating the Layout Logic        117

Adding the Scrolling Functionality      119

Animated Scrolling          122

Taking Scrolling to the Next Step        123

Scrolling Without IScrollInfo        124

Summary            127

8 Virtualization 129

Virtualization Distilled         129

Building Blocks of UI Virtualization       130

UI Virtualization in WPF         131

Component Interaction         132

A Deeper Look at the ItemContainerGenerator    133

Making Our Own Virtualized Control: The StaggeredPanel  135

Deferred Scrolling          139

Container Recycling         140

Virtualization in 3D         140

Summary            142

9 Creating Advanced Controls and Visual Effects 143

Lasso Selection Using the InkCanvas       143

Building a Dock Slide Presenter       146

Docking and Undocking Controls       149

Building a Transition Abstraction: The TransitionContainer   154

Handling Transitions         157

Applying a Transition         159

Implementing Popular Visual Effects       161

Reflection           161

Drop Shadows          163

Opacity Masks          164

Gloss Effects           164

Summary            166

10 Control Skinning and Themes 167

Introduction to Skins and Themes       168

Resource Lookups in WPF        168

Building Default Styles        169

Using Resources in Default Styles        170

Creating Theme-Specific Styles        172

Enabling Runtime Skinning         174

Using the ApplyTemplate Override      177

Control Customization Through Property Exposure     182

Summary            183

Part III Building Interactivity, 3D, Animations

11 Bridging the 2D and 3D Worlds 185

A Brief Introduction to 3D Worlds       185

Using the Viewport3D Element       186

Embedding a Viewport3D Element      189

Mapping 2D Visuals on 3D Surfaces       192

Getting Interactive with ModelUIElement3D and

ContainerUIElement3D        196

2D Bounds of a 3D Object        198

Hints on Layout in 3D        200

Interactive 2D-on-3D Surfaces        200

Summary            201

12 Custom Animations 203

Procedural Animations         203

Animating Using the DispatcherTimer      204

Animating Using CompositionTarget.Rendering     204

Animating with Storyboards        206

Simple Type-Based Animations (From, To, and By)    206

Keyframe Animations         207

Using Storyboards with Parallel Timelines      208

Using Path-Based Animations       211

Creating Custom Animations        212

Creating the 3D Surfaces         219

Animating Within the DrawingContext       220

Summary            221

13 Pixel Shader Effects 223

New and Improved Bitmap Effects       224

Working with Shaders          224

Setting Up the Environment       224

An Overview of HLSL         225

Writing Custom Shaders         228

Grayscale Shader         228

Building a Parameterized Shader: TwirlEffect     231

Animating the Shader Effects       235

Effect Mapping for GUI Interaction and Eventing    235

Multi-Input Shaders         239

A Useful Tool           242

Summary            242

Part IV Bringing the Controls to the Real World

14 Events, Commands, and Focus 243

Routed Events          243

Routed Events, Event Triggers, and Property Mirrors   245

Attached Events          246

Class Handlers          249

Weak Events Using Weak References       250

Implementing the Weak Event Pattern      251

Subclassing the Weak Event Manager      252

Delivering Events Via the IWeakEventListener     254

Commands           255

Routed Commands          259

Commands Versus Events        259

Request Requery         261

The ICommandSource Interface       262

Focus Management         266

Logical and Keyboard Focus        266

Focus-Related Events and Properties       267

Keyboard Navigation         271

Summary            273

15 Advanced Data Binding 275

Dependency Properties         276

Dependency Property Precedence       276

Using AddOwner Instead of Creating a New DependencyProperty  279

Listening to Property Changed Events on Dependency Properties  280

Special Data Binding Scenarios        282

Using RelativeSource.PreviousData      282

Using NotifyOnSourceUpdated and NotifyOnTargetUpdated   284

The Dispatcher and DispatcherPriority       285

Deferring UI Operations         287

Posting Messages from Worker Threads      287

The BackgroundWorker Class       289

Introduction to Continuous LINQ (CLINQ)     291

Summary            292

16 Control and Visual Design Tips 295

Control Design Tips         295

Use Internal Resource Dictionaries      295

Define Complex Controls as Partial Classes     296

Use Scoped Dependency Properties for Internal State Management  296

Use Attached Properties for Adding Functionality    297

Compose Graphics Using Simpler Building Blocks    297

Communicating Between a Control and Its Subparts   297

Use a State Machine to Handle Multiple Events and Property Changes         299

Use Low-Priority Delegates for Noncritical Tasks     299

Use x: Shared for Cloning Resources       299

Use Markup Extensions to Encapsulate Object Creation   300

Useful Patterns for GUI Development      301

The Strategy Pattern         301

The Builder Pattern         301

Model-View-Controller        302

Model-View-View Model         302

Factory Method          303

Composed Method          303

State Pattern           303

Code Should be Idiomatic with Regard to“Framework Design Guidelines”       304

Visual Design Tips          304

Using Tile Brushes          304

Using Gradients with Relative Transforms      306

XAML Coding Conventions        307

Use the Vista Interface Guidelines       308

Using Nonstandard Fonts for Icons      308

Using Transparent PNGs         309

Import from Photoshop and Illustrator      309

Opacity Masks          310

Using Clip Geometries        310

Some Useful Tools          312

Snoop            312

Mole           313

Kaxaml            313

Summary            315

17 Performance 317

Different Kinds of Performance       318

Choice of Visuals         318

Brushes and Caching         320

Resource Management        321

Reference Handling         321

Data Binding and Freezables       321

Background Threads for Long-Running Operations    322

Scrolling and Virtualization        322

Storyboard Animations        323

Pixel Shaders           323

Framework Property Metadata Options      323

RenderCapability–Hardware and Software Rendering    324

Optimizing the Render Pipeline       325

3D            325

Measuring Performance         326

Visual Profiler          327

Perforator           328

Third-Party Tools         329

Perceived Responsiveness        329

Summary            330

18 Control Automation 331

The Need for UI Automation        331

The Automation Object Model        332

Assemblies and Namespaces        333

AutomationElement, AutomationPeer, and Control Patterns   333

Automation Properties        335

Navigating the Automation Tree       336

Using the Automation API        338

Locating Elements in the Automation Tree      339

Checking for Control Patterns        340

Looking Up Property Values        341

Listening to Events          341

Navigating to the Parent, Child, or Sibling      342

Performing Operations on Automation Elements     342

Automation of a Custom Control        343

Picking a Base Peer Class         343

Picking Pattern Interfaces, aka the Control Patterns    344

Building RangeSelectorAutomationPeer      345

Additional Resources          349

Summary            349

Index            351

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020