Tải bản đầy đủ (.pdf) (655 trang)

windows presentation foundation unleashed

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (18.57 MB, 655 trang )

www.it-ebooks.info
UNLEASHED
800 East 96th Street, Indianapolis, Indiana 46240 USA
Adam Nathan
Windows
®
Presentation
Foundation
with Daniel Lehenbauer,
Lead Developer Responsible for WPF 3D
www.it-ebooks.info
Windows Presentation Foundation Unleashed
Copyright © 2007 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or
transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise,
without written permission from the publisher. No patent liability is assumed with respect to
the use of the information contained herein. Although every precaution has been taken in the
preparation of this book, the publisher and author assume no responsibility for errors or omis-
sions. Nor is any liability assumed for damages resulting from the use of the information
contained herein.
International Standard Book Number: 0-672-32891-7
Library of Congress Cataloging-in-Publication Data
Nathan, Adam.
Windows presentation foundation unleashed / Adam Nathan.
p. cm.
ISBN 0-672-32891-7
1. Windows presentation foundation. 2. Application software. 3. Microsoft .NET Framework.
I. Title.
QA76.76.A65N38 2007
005.2’768—dc22
2006038586


Printed in the United States of America
First Printing: December, 2006
04030201 4321
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been
appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information.
Use of a term in this book should not be regarded as affecting the validity of any trademark or
service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but
no warranty or fitness is implied. The information provided is on an “as is” basis. The author
and the publisher shall have neither liability nor responsibility to any person or entity with
respect to any loss or damages arising from the information contained in this book.
Bulk Sales
Pearson Education offers excellent discounts on this book when ordered in quantity for bulk
purchases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419

For sales outside of the U.S., please contact
International Sales

Editor-in-Chief
Karen Gettman
Acquisitions Editor
Neil Rowe
Development Editor
Mark Renfrow
Managing Editor
Gina Kanouse

Project Editor
Betsy Harris
Copy Editor
Karen Annett
Indexers
Lisa Stumpf
Ken Johnson
Proofreader
Kathy Bidnell
Publishing
Coordinator
Cindy Teeters
Book Designer
Gary Adair
Technical Editor
Robert Hogue
Composition
Jake McFarland
www.it-ebooks.info
Contents at a Glance
Introduction 1
PART I Background
1 Why Windows Presentation Foundation? 9
2 XAML Demystified 19
3 Important New Concepts in WPF 45
Part II Building a WPF Application
4 Introducing WPF’s Controls 85
5 Sizing, Positioning, and Transforming Elements 127
6 Layout with Panels 147
7 Structuring and Deploying an Application 191

Part III Features for Professional Developers
8 Resources 239
9 Data Binding 259
10 Styles, Templates, Skins, and Themes 307
Part IV Going Beyond Today’s Applications with Rich Media
11 2D Graphics 355
12 3D Graphics 415
13 Animation 469
14 Audio, Video, Speech, and Documents 501
Part V Advanced Topics
15 Interoperability with Win32, Windows Forms, and ActiveX 539
16 User Controls and Custom Controls 579
17 Layout with Custom Panels 605
Part VI Appendix
Appendix Helpful Tools 617
Index 621
www.it-ebooks.info
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: Features for Professional Developers 5
Part IV: Going Beyond Today’s Applications with Rich Media 5
Part V: Advanced Topics 5
Conventions Used in This Book 6
PART I Background

1 Why Windows Presentation Foundation? 9
A Look at the Past 10
Enter WPF 11
Part of the .NET Framework 16
Designed for Managed Code 16
Emphasis on Declarative Descriptions 17
Conclusion 18
2 XAML Demystified 19
XAML Defined 20
Elements and Attributes 20
Namespaces 22
Property Elements 24
Type Converters 25
Markup Extensions 26
Children of Object Elements 29
The Content Property 29
Collection Items 30
More Type Conversion 32
Compilation: Mixing XAML with Procedural Code 34
Loading and Parsing XAML at Run-Time 34
Compiling XAML 36
XAML Keywords 41
Windows Presentation Foundation Unleashed
iv
www.it-ebooks.info
Conclusion 43
Complaint #1: XML Is Too Verbose to Type 44
Complaint #2: XML-Based Systems Have Poor Performance 44
3 Important New Concepts in WPF 45
Logical and Visual Trees 45

Dependency Properties 51
A Dependency Property Implementation 51
Change Notification 53
Property Value Inheritance 55
Support for Multiple Providers 57
Attached Properties 60
Routed Events 64
A Routed Event Implementation 64
Routing Strategies and Event Handlers 66
Routed Events in Action 66
Attached Events 70
Commands 73
Built-In Commands 74
Executing Commands with Input Gestures 77
Controls with Built-In Command Bindings 78
A Tour of the Class Hierarchy 79
Conclusion 81
Part II Building a WPF Application
4 Introducing WPF’s Controls 85
Content Controls 86
Buttons 87
Simple Containers 91
Containers with a Header 95
Items Controls 97
Selectors 100
Menus 111
Other Items Controls 115
Range Controls 120
ProgressBar 120
Slider 121

Text and Ink Controls 122
TextBox 122
RichTextBox 123
PasswordBox 123
InkCanvas 124
Conclusion 126
Contents
v
www.it-ebooks.info
5 Sizing, Positioning, and Transforming Elements 127
Controlling Size 128
Height and Width 128
Margin and Padding 130
Visibility 132
Controlling Position 133
Alignment 133
Content Alignment 134
FlowDirection 135
Applying Transforms 136
RotateTransform 138
ScaleTransform 139
SkewTransform 142
TranslateTransform 142
MatrixTransform 142
Combining Transforms 143
Conclusion 145
6 Layout with Panels 147
Canvas 148
StackPanel 151
WrapPanel 152

DockPanel 155
Grid 157
Sizing the Rows and Columns 161
Interactive Sizing with GridSplitter 164
Sharing Row and Column Sizes 166
Comparing Grid to Other Panels 168
Primitive Panels 169
TabPanel 169
ToolBarOverflowPanel 170
ToolBarTray 170
UniformGrid 170
Handling Content Overflow 170
Clipping 171
Scrolling 173
Scaling 175
Putting It All Together: Creating a Visual Studio-Like Collapsible,
Dockable, Resizable Pane 179
Conclusion 189
Windows Presentation Foundation Unleashed
vi
www.it-ebooks.info
7 Structuring and Deploying an Application 191
Standard Windows Applications 191
The Window Class 192
The Application Class 195
Creating and Showing Dialogs 201
Persisting and Restoring Application State 204
Deployment: ClickOnce Versus Windows Installer 205
Navigation-Based Windows Applications 206
Pages and Their Navigation Containers 207

Navigating from Page to Page 209
Passing Data Between Pages 215
Applications with a Windows Vista Look and Feel 218
Going Beyond MessageBox with TaskDialog 219
Using Aero Glass 221
Gadget-Style Applications 225
XAML Browser Applications 227
Limited Feature Set 229
Integrated Navigation 231
Deployment 232
Loose XAML Pages 235
Conclusion 236
Part III Features for Professional Developers
8 Resources 239
Binary Resources 239
Defining Binary Resources 240
Accessing Binary Resources 241
Localization 246
Logical Resources 247
Resource Lookup 250
Static Versus Dynamic Resources 251
Interaction with System Resources 256
Conclusion 256
9 Data Binding 259
Introducing the Binding Object 259
Using Binding in Procedural Code 259
Using Binding in XAML 262
Binding to Plain .NET Properties 263
Binding to an Entire Object 265
Binding to a Collection 267

Sharing the Source with DataContext 270
Contents
vii
www.it-ebooks.info
Controlling Rendering 271
Using Data Templates 271
Using Value Converters 274
Customizing the View of a Collection 279
Sorting 279
Grouping 281
Filtering 284
Navigating 285
Working with Additional Views 286
Data Providers 288
XmlDataProvider 289
ObjectDataProvider 293
Advanced Topics 296
Customizing the Data Flow 296
Adding Validation Rules to Binding 298
Working with Disjoint Sources 301
Putting It All Together: The Pure-XAML RSS Reader 303
Conclusion 305
10 Styles, Templates, Skins, and Themes 307
Styles 308
Sharing Styles 310
Triggers 316
Templates 321
Introducing Control Templates 321
Getting Interactivity with Triggers 322
Restricting the Target Type 324

Respecting the Templated Parent’s Properties 325
Respecting Visual States 332
Mixing Templates with Styles 338
Skins 340
Themes 346
Using System Colors, Fonts, and Parameters 347
Per-Theme Styles and Templates 348
Conclusion 351
Part IV Going Beyond Today’s Applications with Rich Media
11 2D Graphics 355
Drawings 356
Geometries 358
Pens 369
Clip Art Example 370
Windows Presentation Foundation Unleashed
viii
www.it-ebooks.info
Visuals 372
Filling a DrawingVisual with Content 373
Displaying a Visual on the Screen 376
Visual Hit Testing 378
Shapes 385
Rectangle 386
Ellipse 387
Line 388
Polyline 388
Polygon 389
Path 390
Clip Art Based on Shapes 391
Brushes 392

Color Brushes 392
Tile Brushes 399
Brushes as Opacity Masks 406
Bitmap Effects 409
Conclusion 413
12 3D Graphics 415
Getting Started with 3D Graphics 416
Cameras and Coordinate Systems 420
The Position Property 420
LookDirection 422
UpDirection 425
Orthographic Versus Perspective 428
Transform3Ds 430
TranslateTransform3Ds 433
ScaleTransform3Ds 433
RotateTransform3Ds 436
Combining Transform3Ds 439
Model3Ds 439
Lights 440
GeometryModel3Ds 447
Model3DGroup 459
Visual3Ds 462
ModelVisual3Ds 462
3D Hit Testing 464
The Viewport3D Element 465
Conclusion 468
Contents
ix
www.it-ebooks.info
13 Animation 469

Animations in Procedural Code 470
Performing Animation “By Hand” 470
Introducing the Animation Classes 471
Simple Animation Tweaks 478
Animations in XAML 483
EventTriggers Containing Storyboards 483
Using Storyboard as a Timeline 490
Keyframe Animations 492
Linear Keyframes 492
Spline Keyframes 495
Discrete Keyframes 496
Conclusion 499
14 Audio, Video, Speech, and Documents 501
Audio 501
SoundPlayer 502
SoundPlayerAction 502
MediaPlayer 503
MediaElement and MediaTimeline 504
Video 506
Controlling the Visual Aspects of MediaElement 506
Controlling the Underlying Media 509
Speech 512
Speech Synthesis 512
Speech Recognition 515
Documents 519
Creating Flow Documents 520
Displaying Flow Documents 530
Adding Annotations 532
Conclusion 535
Part V Advanced Topics

15 Interoperability with Win32, Windows Forms, and ActiveX 539
Embedding Win32 Controls in WPF Applications 541
A Win32 Webcam Control 541
Using the Webcam Control in WPF 545
Supporting Keyboard Navigation 551
Embedding WPF Controls in Win32 Applications 556
Introducing HwndSource 556
Getting the Right Layout 559
Windows Presentation Foundation Unleashed
x
www.it-ebooks.info
Embedding Windows Forms Controls in WPF Applications 563
Embedding a PropertyGrid with Procedural Code 564
Embedding a PropertyGrid with XAML 566
Embedding WPF Controls in Windows Forms Applications 567
Embedding ActiveX Controls in WPF Applications 572
Conclusion 576
16 User Controls and Custom Controls 579
Creating a User Control 581
Creating the User Interface 581
Creating the Behavior 583
Adding Dependency Properties 586
Adding Routed Events 589
Creating a Custom Control 590
Creating the Behavior 591
Creating the User Interface 597
Considerations for More Sophisticated Controls 601
Conclusion 604
17 Layout with Custom Panels 605
Communication Between Parents and Children 606

The Measure Step 606
The Arrange Step 608
Creating a 2007 Office-Like RibbonPanel 609
RibbonPanel Behavior 609
RibbonPanel Implementation 610
Conclusion 614
Part VI Appendix
Appendix Helpful Tools 617
Professional Development Tools 617
Free Utilities 618
Professional Design Tools 620
Index 621
Contents
xi
www.it-ebooks.info
About the Authors
Adam Nathan is a senior software development engineer in Microsoft’s Developer
Division. He is the author of the acclaimed .NET and COM: The Complete Interoperability
Guide (SAMS, 2002), a coauthor of ASP.NET: Tips, Tutorials, and Code (SAMS, 2001), and a
contributor to books such as .NET Framework Standard Library Annotated Reference, Vol. 2
(Addison-Wesley, 2005) and Windows Developer Power Tools (O’Reilly, 2006).
Adam regularly speaks at development conferences and to groups within Microsoft about
a variety of .NET Framework topics. Having started his career on Microsoft’s Common
Language Runtime team in 1999, Adam has been at the core of .NET technologies since
the very beginning. Adam is also the creator of popular tools and websites for .NET
developers, such as PINVOKE.NET, CLR SPY (and its Visual Studio add-in), and
XAMLshare.com. You can find him online at www.adamnathan.net.
Daniel Lehenbauer is the lead software design engineer responsible for the 3D
features in Windows Presentation Foundation. Prior to WPF, he worked on multiple
graphics and UI technologies, including mobile controls for ASP.NET and Windows

Forms. Daniel is active in the WPF community and blogs about 3D graphics using WPF
at www.viewport3D.com.
www.it-ebooks.info
Dedication
To Lindsay and Tyler.
www.it-ebooks.info
Acknowledgments
First and foremost, I’d like to not only thank my wife, Lindsay, but somehow attempt to
apologize to her. Unfortunately, I know that nothing I write can come close to making up
for what I’ve put her through over the last year. In the midst of writing this book, I real-
ized two things that I’m sure my wife has known all along: I can’t write a book shorter
than 500 pages, and I can’t write a book without neglecting my family.
As if it weren’t bad enough that I wrote my first book during our first year of marriage, I
wrote this book during our first year of parenthood. Although I was able to do most of
the writing after our son went to bed, I robbed the two of us of any significant quality
time for far too long. Yet Lindsay showed incredible patience and understanding through-
out the entire process—much more than I deserved. As my schedule got extra hectic
toward the end, she kept me on track, helped me get out of bed at 5 AM, and helped me
stay healthy. She even weighed in (over my shoulder) with her own thoughts as I revised
chapters! In short, she took care of me, our son, our house, and all aspects of our life
while I was preoccupied in front of my silly little computer. And she did all this with
grace and humility. Lindsay, I love you, and I’m sorry.
Although most of the process of writing a book is very solitary, this book came together
because of the work of many talented and hard-working people. I’d like to take a moment
to thank some of them by name.
Daniel Lehenbauer, the lead developer responsible for the 3D features in WPF, deserves an
enormous amount of thanks for agreeing to contribute a chapter on 3D that is far better
than anything I could have written myself. Having Daniel’s perspective and advice captured
on paper is a huge benefit for any readers thinking about dabbling in 3D. Daniel also thor-
oughly reviewed other chapters in this book and provided invaluable feedback.

Many other Microsoft co-workers graciously agreed to review chapters and provided
wonderful feedback. I’d like to thank (in alphabetical order) Beatriz de Oliveira Costa,
Robert Hogue, Neil Kronlage, Mike Mueller, Oleg Ovetchkine, S. Ramini, Rob Relyea,
Adam Smith, and Tim Sneath. I also thank Lori Pearce and David Treadwell for giving me
permission to write this book in the first place.
I’d like to sincerely thank the folks at Sams—especially Neil Rowe—because I couldn’t
have asked for a better publishing team. Never once was I told that my content was too
long or too short or too different from a typical “Unleashed” title. I was never even told
that I was taking too much time (although I did get some gentle hints along the way)!
They gave me the complete freedom to write the kind of book I wanted to write. And
when I asked Neil if there was any way that we could print the book in full color, he not
only made it happen but came up with the innovative idea to print the code samples
with complete syntax coloring!
www.it-ebooks.info
I’d like to thank my family for opening my eyes to the world of computer programming
when I was in elementary school. If you have children, please expose them to the magic
of writing software while they’re still young enough to care about what you have to say!
(WPF can even help you make the experience fun!)
Finally, I thank you for picking up a copy of this book and reading at least this far! I hope
you continue reading and find the journey of exploring WPF as fascinating as I have!
www.it-ebooks.info
Tell Us What You Think!
As the reader of this book, you are our most important critic and commentator. We value
your opinion and want to know what we’re doing right, what we could do better, what
areas you’d like to see us publish in, and any other words of wisdom you’re willing to
pass our way.
As a Senior Acquisitions Editor for Sams, I welcome your comments. You can fax, email,
or write me directly to let me know what you did or didn’t like about this book—as well
as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book, and

that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book’s title and author as well as your
name and email address, phone, or fax number. I will carefully review your comments
and share them with the author and editors who worked on the book.
Email:
Fax: 317-428-3310
Mail: Neil Rowe, Senior Acquisitions Editor
Sams Publishing
800 East 96th Street
Indianapolis, IN 46240 USA
www.it-ebooks.info
Introduction
Thank you for picking up Windows Presentation Foundation Unleashed! To avoid unsatisfied
customers, I want to clarify that this is not a book about Microsoft PowerPoint (which
many people consider to be the foundation of Windows presentations)! Windows
Presentation Foundation (WPF) is Microsoft’s latest technology for creating graphical user
interfaces, whether they consist of plain forms, document-centric windows, animated
cartoons, videos, immersive 3D environments, or all of the above! This is a technology
that makes it easier than ever to create a broad range of applications. For example, WPF
makes it relatively straightforward to implement applications similar to Windows Media
Player, Microsoft Word (or at least WordPad), and, yes, even Microsoft PowerPoint!
Ever since WPF was publicly announced in 2003 (with the code name of “Avalon”), it has
gotten considerable (and deserved) attention for the ways in which it revolutionizes the
process of creating software—especially for Windows programmers used to Windows Forms
and GDI. It’s relatively easy to create fun, useful, and shareable WPF samples that demon-
strate all kinds of techniques that are difficult to accomplish in other technologies. But
WPF is quite a departure from previous technologies in terms of its programming model,
underlying concepts, and basic terminology. Even viewing the source code for WPF (by
cracking open its components with a tool like .NET Reflector) is a confusing experience
because the code you’re looking for often doesn’t reside where you’d expect. When you

combine all of this with the fact that there are often several ways to accomplish any task,
you arrive at a conclusion shared by many: WPF has a very steep learning curve.
That’s where this book comes in. Five years ago, I wrote .NET and COM: The Complete
Interoperability Guide because I felt there was a need for an entire book to guide people
through such a deep and complex topic. As WPF was developed, it was obvious that there
would be no shortage of WPF books in the marketplace. But it wasn’t clear to me that the
books would have the right balance to guide people through the technology and its
unique concepts while showing practical ways to exploit it. Therefore, I wrote Windows
Presentation Foundation Unleashed with the following goals in mind:
. To provide a solid grounding in the underlying concepts in a practical and
approachable fashion
. To answer the questions most people have when learning the technology, and to
show how commonly desired tasks are accomplished
. To be an authoritative source, thanks to input from members of the WPF team who
designed, implemented, and tested the technology
. To be clear about where the technology falls short, rather than selling the technol-
ogy as the answer to all problems
. To be an easily navigated reference that you can constantly come back to
I hope you find this book to exhibit all of these attributes.
www.it-ebooks.info
Who Should Read This Book?
This book is for software developers who are interested in user interfaces. Regardless of
whether you’re creating line-of-business applications, consumer-facing applications, or
reusable controls, this book contains a lot of content that helps you get the most out of
the platform. It’s designed to be understandable even for folks who are new to .NET. And
if you are already well versed in WPF, I’m confident that this book still has things to teach
you. At the very least, it should be an invaluable reference for your bookshelf.
Because WPF enables you to create not only standalone Windows applications but also
content hosted in a web browser, anyone interested in alternatives to Adobe Flash might
find this book interesting. And although the more lightweight and cross-platform

Windows Presentation Foundation Everywhere (WPF/E) technology does not have signifi-
cant coverage in this book, many of the same concepts in this book will apply to WPF/E
once it is released.
Although this book’s content is not optimized for graphic designers, reading this book
can be a great way to understand more of the “guts” behind a product like Microsoft
Expression Blend.
To summarize, this book
. Covers everything you need to know about Extensible Application Markup
Language (XAML), the new XML-based language for creating declarative user inter-
faces that can be easily restyled
. Examines the WPF feature areas in incredible depth: controls, layout, resources, data
binding, styling, graphics, animation, and more
. Delves into topics that aren’t covered by most books: 3D, speech, audio/video, docu-
ments, bitmap effects, and more
. Shows how to create popular UI elements, such as features introduced in the 2007
Microsoft Office System: Galleries, ScreenTips, custom control layouts, and more
. Demonstrates how to create sophisticated UI mechanisms, such as Visual Studio-like
collapsible/dockable panes
. Explains how to develop and deploy all types of applications, including navigation-
based applications, applications hosted in a web browser, and applications with
great-looking nonrectangular windows
. Explains how to create first-class custom controls for WPF
. Demonstrates how to create hybrid WPF software that leverages Windows Forms,
ActiveX, or other non-WPF technologies
. Explains how to exploit new Windows Vista features in WPF applications, and how
to go beyond certain limitations of WPF
INTRODUCTION
2
www.it-ebooks.info
This book doesn’t cover every last bit of WPF. (In particular, XML Paper Specification

[XPS] documents are only given a small bit of attention.) WPF’s surface area is so large
that I don’t believe any single book can. But I think you’ll be pleased with the breadth
and depth achieved by this book.
Examples in this book appear in XAML and C#, plus C++/CLI for interoperability discus-
sions. XAML is used heavily for a number of reasons: It’s often the most concise way to
express source code, it can often be pasted into tools like XamlPad (in the Windows SDK)
to see instant results without any compilation, WPF-based tools generate XAML rather
than procedural code, and XAML is applicable no matter what .NET language you use,
such as Visual Basic instead of C#. Whenever the mapping between XAML and a language
like C# is not obvious, examples are shown in both representations.
Software Requirements
This book targets the final release of version 3.0 of Windows Presentation Foundation, the
corresponding Windows SDK, and the October 2006 release of .NET Framework 3.0 exten-
sions to Visual Studio 2005.
The following software is required:
. A version of Windows that supports the .NET Framework 3.0. This can be Windows
XP with Service Pack 2 (including Media Center, Tablet PC, and x64 editions),
Windows Server 2003 with Service Pack 1 (including the R2 edition), Windows
Vista, or later versions.
. The .NET Framework 3.0, which is installed by default starting with Windows Vista.
For earlier versions of Windows, you can download it for free from
.
In addition, the following software is recommended:
. The Windows Software Development Kit (SDK), specifically the .NET tools it
includes. This is also a free download from .
. Visual Studio 2005 or later, which can be a free Express edition downloaded from
. If you’re using a 2005 edition of Visual Studio (Express or other-
wise), you should download the extensions for .NET Framework 3.0 development
available from MSDN. This is not necessary for later versions of Visual Studio.
If you want additional tool support for WPF-based graphic design, Microsoft Expression

can be extremely helpful. See the appendix, “Helpful Tools,” for other pieces of software
that can be helpful for WPF design and development.
A few examples in Chapter 7, “Structuring and Deploying an Application,” are specific to
Windows Vista, but the rest of the book applies equally to all relevant versions of
Windows.
Software Requirements
3
www.it-ebooks.info
Code Examples
The source code for examples in this book can be downloaded via
www.samspublishing.com or www.adamnathan.net/wpf.
How This Book Is Organized
This book is arranged into five main parts, representing the progression of feature areas
that you typically need to understand to use WPF effectively. But if you’re dying to jump
ahead and learn about a topic such as 3D or animation, the book is set up to allow for
nonlinear journeys as well. The following sections provide a summary of each part.
Part I: Background
The book introduces WPF by comparing it to alternative technologies and helping you
make decisions about when WPF is appropriate for your needs. Chapter 2 explores XAML
in great depth, giving you the foundation to understand the XAML you’ll encounter in
the rest of the book and in real life. Chapter 3 highlights the most unique pieces of WPF’s
programming model above and beyond what .NET programmers already understand.
. Chapter 1: Why Windows Presentation Foundation?
. Chapter 2: XAML Demystified
. Chapter 3: Important New Concepts in WPF
Part II: Building a WPF Application
Part II equips you with the knowledge to assemble and deploy a traditional-looking appli-
cation (although some fancier effects like transforms, non-rectangular windows, and Aero
glass are also covered). It begins by introducing WPF’s implementation of controls you’d
expect to have available, plus a few that you might not expect. It then devotes two chap-

ters to arranging such controls (and other elements) in a user interface. Chapter 7 ends
this part by examining several different ways to take WPF-based user interfaces and
package and deploy complete applications. This not only includes traditional standalone
Windows applications, but also applications that are more like web pages.
. Chapter 4: Introducing WPF’s Controls
. Chapter 5: Sizing, Positioning, and Transforming Elements
. Chapter 6: Layout with Panels
. Chapter 7: Structuring and Deploying an Application
INTRODUCTION
4
www.it-ebooks.info
Part III: Features for Professional Developers
The features covered in Part III are not always necessary to use in WPF applications, but
they can greatly enhance the development process. Therefore, they tend to be indispens-
able for professional developers who are serious about creating maintainable and robust
applications or components.
. Chapter 8: Resources
. Chapter 9: Data Binding
. Chapter 10: Styles, Templates, Skins, and Themes
Part IV: Going Beyond Today’s Applications with Rich Media
This part of the book covers the features in WPF that typically get the most attention. The
support for 2D and 3D graphics, animation, video, and more enable you to create a stun-
ning experience. These features—and the way they are exposed—set WPF apart from
previous systems. WPF lowers the barrier to incorporating such content in your software,
so you might try some of these features that you never would have dared to in the past!
. Chapter 11: 2D Graphics
. Chapter 12: 3D Graphics
. Chapter 13: Animation
. Chapter 14: Audio, Video, Speech, and Documents
Part V: Advanced Topics

The topics covered in Part V are relevant for advanced application developers, or develop-
ers of WPF-based controls. Because existing WPF controls can be radically restyled, the
need for creating custom controls is greatly reduced.
. Chapter 15: Interoperability with Win32, Windows Forms, and ActiveX
. Chapter 16: User Controls and Custom Controls
. Chapter 17: Layout with Custom Panels
How This Book Is Organized
5
www.it-ebooks.info
Conventions Used in This Book
Various typefaces in this book identify terms and other special items. These typefaces
include the following:
Typeface Meaning
Italic Italic is used for new terms or phrases when they are initially defined,
and occasionally for emphasis.
Monospace Monospace is used for screen messages, code listings, and command
samples, as well as filenames. In code listings,
italic monospace
type is used for placeholder text.
Code listings are colorized similar to the way they are colorized in
Visual Studio.
Blue monospace type
is used for XML elements and
C#/C++ keywords,
brown monospace type
is used for XML element
names and C#/C++ strings,
green monospace type
is used for
comments,

red monospace type
is used for XML attributes, and
teal
monospace type
is used for type names in C# and C++.
Throughout this book, you’ll find the following sidebar elements:
. FAQ (Frequently Asked Question) sidebars present a question readers might have
regarding the subject matter in a particular spot in the book—then it provides a
concise answer.
. Digging Deeper sidebars present advanced or more detailed information on a subject
than is provided in the text surrounding them. Think of Digging Deeper material as
stuff you can look into if you’re curious, but can ignore if you’re not.
. Tips are bits of information that can help you in real-world situations. They often
offer shortcuts or alternative approaches to make a task easier, quicker, or produce
better results.
. Warnings alert you to an action or condition that can lead to an unexpected or
unpredictable result, and then tell you how to avoid it.
INTRODUCTION
6
www.it-ebooks.info
PART I
Background
IN THIS PART
CHAPTER 1 Why Windows Presentation 9
Foundation?
CHAPTER 2 XAML Demystified 19
CHAPTER 3
Important New Concepts in WPF 45
www.it-ebooks.info
This page intentionally left blank

www.it-ebooks.info

×