Home > Store

WPF 4 Unleashed

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

WPF 4 Unleashed

Book

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

Description

  • Copyright 2011
  • Dimensions: 7" x 9-1/8"
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-33119-5
  • ISBN-13: 978-0-672-33119-0

The #1 WPF Book--Now Updated for WPF 4!

Full Color: Code samples appear as they do in Visual Studio!

Thorough, authoritative coverage, practical examples, clear writing, and full-color presentation make this one of the most widely acclaimed programming books of the last decade.

Windows Presentation Foundation (WPF) is the recommended technology for creating Windows user interfaces, giving you the power to create richer and more compelling applications than you dreamed possible. Whether you want to develop traditional user interfaces or integrate 3D graphics, audio/video, animation, dynamic skinning, multi-touch, rich document support, speech recognition, or more, WPF enables you to do so in a seamless, resolution-independent manner. WPF 4 Unleashed is the authoritative book that covers it all, in a practical and approachable fashion, authored by WPF guru and Microsoft developer Adam Nathan. 

  • Covers everything you need to know about Extensible Application Markup Language (XAML)
  • Examines the WPF feature areas in incredible depth: controls, layout, resources, data binding, styling, graphics, animation, and more
  • Highlights the latest features, such as multi-touch, text rendering improvements, XAML language enhancements, new controls, the Visual State Manager, easing functions, and much more
  • Delves into topics that aren’t covered by most books: 3D, speech, audio/video, documents, effects
  • Shows how to create popular UI elements, such as Galleries, ScreenTips, and more
  • Demonstrates how to create sophisticated UI mechanisms, such as Visual Studio-like collapsible/dockable panes
  • Explains how to create first-class custom controls for WPF
  • Demonstrates how to create hybrid WPF software that leverages Windows Forms, DirectX, ActiveX, or other non-WPF technologies
  • Explains how to exploit new Windows 7 features, such as Jump Lists and taskbar customizations

Downloads

Downloads

Download the source code

Sample Content

Online Sample Chapter

Why WPF, and What About Silverlight?

Sample Pages

Download the sample pages (includes Chapter 1 and Index)

Table of Contents

Introduction     1

Who Should Read This Book?      2

Software Requirements     3

Code Examples     4

How This Book Is Organized     4

Part I: Background     4

Part II: Building a WPF Application     4

Part III: Controls     5

Part IV: Features for Professional Developers     5

Part V: Rich Media     5

Part VI: Advanced Topics     6

Conventions Used in This Book     6

Part I Background

Chapter 1: Why WPF, and What About Silverlight?      9

A Look at the Past      10

Enter WPF     11

The Evolution of WPF     14

Enhancements in WPF 3.5 and WPF 3.5 SP1     15

Enhancements in WPF 4     16

What About Silverlight?      18

Summary     19

Chapter 2: XAML Demystified     21

XAML Defined     23

Elements and Attributes     24

Namespaces      26

Property Elements     29

Type Converters     30

Markup Extensions     32

Children of Object Elements .      35

The Content Property     35

Collection Items     36

More Type Conversion     38

Mixing XAML with Procedural Code     40

Loading and Parsing XAML at Runtime     40

Compiling XAML     43

Introducing XAML2009     48

Full Generics Support     49

Dictionary Keys of Any Type     50

Built-In System Data Types     50

Instantiating Objects with Non-Default Constructors     51

Getting Instances via Factory Methods     51

Event Handler Flexibility     52

Defining New Properties     53

Fun with XAML Readers and Writers     53

Overview     53

The Node Loop     56

Reading XAML     57

Writing to Live Objects      61

Writing to XML     63

XamlServices     64

XAML Keywords     67

Summary     70

Complaint 1: XML Is Too Verbose to Type     71

Complaint 2: XML-Based Systems Have Poor Performance     71

Chapter 3: WPF Fundamentals     73

A Tour of the Class Hierarchy     73

Logical and Visual Trees     75

Dependency Properties     80

A Dependency Property Implementation     81

Change Notification     83

Property Value Inheritance     85

Support for Multiple Providers     87

Attached Properties     89

Summary     93

Part II Building a WPF Application

Chapter 4: Sizing, Positioning, and Transforming Elements     97

Controlling Size     98

Height and Width     98

Margin and Padding     100

Visibility     102

Controlling Position     103

Alignment     103

Content Alignment     104

FlowDirection     105

Applying Transforms     106

RotateTransform     108

ScaleTransform.      109

SkewTransform.      112

TranslateTransform     112

MatrixTransform     112

Combining Transforms     113

Summary     114

Chapter 5: Layout with Panels     115

Canvas     116

StackPanel     118

WrapPanel     120

DockPanel     122

Grid     125

Sizing the Rows and Columns     130

Interactive Sizing with GridSplitter     132

Sharing Row and Column Sizes     134

Comparing Grid to Other Panels     136

Primitive Panels     137

TabPanel     137

ToolBarPanel     138

ToolBarOverflowPanel     138

ToolBarTray .      138

UniformGrid.      138

SelectiveScrollingGrid.      138

Handling Content Overflow     139

Clipping     139

Scrolling     141

Scaling     143

Putting It All Together: Creating a Visual Studio—Like Collapsible, Dockable, Resizable Pane     147

Summary      157

Chapter 6: Input Events: Keyboard, Mouse, Stylus, and Multi-Touch     159

Routed Events     159

A Routed Event Implementation     160

Routing Strategies and Event Handlers     161

Routed Events in Action     162

Attached Events     165

Keyboard Events     168

Mouse Events     170

MouseEventArgs     171

Drag and Drop     172

Capturing the Mouse     173

Stylus Events     174

StylusDevice     174

Events     175

Multi-Touch Events     176

Basic Touch Events     177

Manipulation Events for Panning, Rotating, and Zooming     180

Commands     188

Built-In Commands     189

Executing Commands with Input Gestures     192

Controls with Built-In Command Bindings     193

Summary     194

Chapter 7: Structuring and Deploying an Application     195

Standard Windows Applications     195

The Window Class     196

The Application Class     199

Showing a Splash Screen     205

Creating and Showing Dialogs     206

Persisting and Restoring Application State     209

Deployment: ClickOnce Versus Windows Installer     210

Navigation-Based Windows Applications     211

Pages and Their Navigation Containers     212

Navigating from Page to Page     214

Passing Data Between Pages     219

Gadget-Style Applications     223

XAML Browser Applications     224

Limited Feature Set     226

Integrated Navigation      228

Deployment      229

Loose XAML Pages     231

Summary     232

Chapter 8: Exploiting Windows 7     233

Jump Lists     233

JumpTask     234

JumpPath     241

Taskbar Item Customizations     245

Using a Taskbar Item Progress Bar     246

Adding an Overlay to the Taskbar Item     247

Customizing the Thumbnail Content     247

Adding Thumb Buttons to the Taskbar Thumbnail     248

Aero Glass     249

TaskDialog     253

Summary     256

Part III Controls

Chapter 9: Content Controls     261

Buttons     263

Button     264

RepeatButton     265

ToggleButton     265

CheckBox     266

RadioButton     266

Simple Containers     268

Label     268

ToolTip     269

Frame     271

Containers with Headers     272

GroupBox     273

Expander     273

Summary     274

Chapter 10: Items Controls     275

Common Functionality     276

DisplayMemberPath     277

ItemsPanel     278

Controlling Scrolling Behavior     280

Selectors     281

ComboBox     282

ListBox     287

ListView     290

TabControl     291

DataGrid     292

Menus     298

Menu     298

ContextMenu     301

Other Items Controls     302

TreeView     302

ToolBar     304

StatusBar     307

Summary     308

Chapter 11: Images, Text, and Other Controls     309

The Image Control      309

Text and Ink Controls      311

TextBlock     313

TextBox     315

RichTextBox     316

PasswordBox     316

InkCanvas     316

Documents     318

Creating Flow Documents     318

Displaying Flow Documents     329

Adding Annotations     331

Range Controls     334

ProgressBar     335

Slider     335

Calendar Controls     336

Calendar     336

DatePicker     338

Summary     339

Part IV Features for Professional Developers

Chapter 12: Resources     343

Binary Resources     343

Defining Binary Resources     344

Accessing Binary Resources     345

Localizing Binary Resources     350

Logical Resources     351

Resource Lookup     355

Static Versus Dynamic Resources     355

Interaction with System Resources     360

Summary     362

Chapter 13: Data Binding     363

Introducing the Binding Object     363

Using Binding in Procedural Code     363

Using Binding in XAML     365

Binding to Plain .NET Properties     367

Binding to an Entire Object     369

Binding to a Collection     370

Sharing the Source with DataContext     374

Controlling Rendering     375

String Formatting     375

Using Data Templates     378

Using Value Converters     381

Customizing the View of a Collection     386

Sorting     386

Grouping     388

Filtering     392

Navigating     392

Working with Additional Views     394

Data Providers     396

XmlDataProvider     397

ObjectDataProvider     401

Advanced Topics     403

Customizing the Data Flow     403

Adding Validation Rules to Binding     405

Working with Disjoint Sources     409

Putting It All Together: The Pure-XAML Twitter Client     412

Summary     414

Chapter 14: Styles, Templates, Skins, and Themes     415

Styles     416

Sharing Styles     418

Triggers     423

Templates     430

Introducing Control Templates     431

Getting Interactivity with Triggers     432

Restricting the Target Type     434

Respecting the Templated Parent’s Properties     435

Respecting Visual States with Triggers     442

Respecting Visual States with the Visual State Manager (VSM)      447

Mixing Templates with Styles     456

Skins     458

Themes     465

Using System Colors, Fonts, and Parameters     465

Per-Theme Styles and Templates     466

Summary     470

Part V Rich Media

Chapter 15: 2D Graphics     475

Drawings     476

Geometries     479

Pens     489

Clip Art Example     491

Visuals     493

Filling a DrawingVisual with Content     493

Displaying a Visual on the Screen     496

Visual Hit Testing     499

Shapes     505

Rectangle     507

Ellipse     508

Line     509

Polyline     510

Polygon     511

Path     511

Clip Art Based on Shapes     512

Brushes     513

Color Brushes     513

Tile Brushes     520

Brushes as Opacity Masks     527

Effects     529

Improving Rendering Performance     532

RenderTargetBitmap     532

BitmapCache     533

BitmapCacheBrush     535

Summary     535

Chapter 16: 3D Graphics     537

Getting Started with 3D Graphics     538

Cameras and Coordinate Systems     542

Position     543

LookDirection     544

UpDirection     548

OrthographicCamera Versus PerspectiveCamera     551

Transform3D     554

TranslateTransform3D     556

ScaleTransform3D     557

RotateTransform3D     559

Combining Transform3Ds     562

Model3D     563

Lights     563

GeometryModel3D     571

Model3DGroup     584

Visual3D     586

ModelVisual3D     587

UIElement3D     588

Viewport2DVisual3D     590

3D Hit Testing     592

Viewport3D     593

2D and 3D Coordinate System Transformation     596

Visual.TransformToAncestor     596

Visual3D.TransformToAncestor and Visual3D.TransformToDescendant     600

Summary     605

Chapter 17: Animation     607

Animations in Procedural Code     608

Performing Animation “By Hand”      608

Introducing the Animation Classes     609

Simple Animation Tweaks     616

Animations in XAML     621

EventTriggers Containing Storyboards     621

Using Storyboard as a Timeline     629

Keyframe Animations     630

Linear Keyframes     631

Spline Keyframes     633

Discrete Keyframes     634

Easing Keyframes     636

Easing Functions     637

Built-In Power Easing Functions     637

Other Built-In Easing Functions     639

Writing Your Own Easing Function     640

Animations and the Visual State Manager     643

Transitions     647

Summary     651

Chapter 18: Audio, Video, and Speech     653

Audio     653

SoundPlayer     654

SoundPlayerAction     654

MediaPlayer     655

MediaElement and MediaTimeline     656

Video     658

Controlling the Visual Aspects of MediaElement     658

Controlling the Underlying Media     661

Speech     664

Speech Synthesis     664

Speech Recognition     667

Summary     672

Part VI Advanced Topics

Chapter 19: Interoperability with Non-WPF Technologies     675

Embedding Win32 Controls in WPF Applications     677

A Win32 Webcam Control     678

Using the Webcam Control in WPF     681

Supporting Keyboard Navigation     687

Embedding WPF Controls in Win32 Applications     692

Introducing HwndSource     692

Getting the Right Layout     696

Embedding Windows Forms Controls in WPF Applications     699

Embedding a PropertyGrid with Procedural Code     700

Embedding a PropertyGrid with XAML     702

Embedding WPF Controls in Windows Forms Applications     704

Mixing DirectX Content with WPF Content     708

Embedding ActiveX Controls in WPF Applications     714

Summary     718

Chapter 20: User Controls and Custom Controls     721

Creating a User Control     723

Creating the User Interface of the User Control     723

Creating the Behavior of the User Control     725

Adding Dependency Properties to the User Control     728

Adding Routed Events to the User Control     731

Creating a Custom Control     732

Creating the Behavior of the Custom Control     733

Creating the User Interface of the Custom Control     739

Considerations for More Sophisticated Controls     743

Summary     750

Chapter 21: Layout with Custom Panels     751

Communication Between Parents and Children     752

The Measure Step     752

The Arrange Step     754

Creating a SimpleCanvas     755

Creating a SimpleStackPanel     760

Creating an OverlapPanel     763

Creating a FanCanvas     768

Summary     773

Index     775

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