Print this page Share

Professional WPF Programming: .NET Development with the Windows Presentation Foundation

ISBN: 978-0-470-17502-6
650 pages
April 2007
Professional WPF Programming: .NET Development with the Windows Presentation Foundation (0470175028) cover image


Professional WPF Programming

If you want to learn how to build killer user interfaces for Windows and the web, then this book is for you. It arms you with the tools and code you'll need to effectively utilize the Windows Presentation Foundation (WPF). From creating appealing graphics and animated structures to enhancing performance and security, you'll be programming in no time.

First you'll explore the WPF framework and learn how to develop basic applications with ASP.NET or Visual Basic(r). Next you'll discover how to build more sophisticated WPF interfaces using Microsoft(r) ExpressionBlend and then progress to more advanced programming techniques.

Throughout the book, you'll find best practices for enterprise architectures using the WPF and its underlying technology. All this will help you quickly learn how to develop next-generation applications on the .NET 2.0 platform using the WPF.

What you will learn from this book

  • How to write applications with identical UIs on both Windows and the web
  • Tips for collaborating design and code development with Microsoft(r) Expression Blend
  • All about the object models, built-in server controls, HTML markup, code-behind, and the coordinative structure of each file
  • How to migrate Win32 applications to WPF
  • Techniques for integrating special effects and custom controls into an application
  • Advanced development concepts, including building workflows and a WCF service

Who this book is for

This book is for experienced .NET developers who want to begin creating WPF web and desktop applications.

Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.

See More

Table of Contents

Acknowledgments ix

Introduction xix

Chapter 1: Overview of Windows Presentation Foundation 1

A Brief History of the Windows API 2

Platform Evolution 2

Introducing .NET Framework 3.0 3

Meet Windows Presentation Foundation 3

Guiding Design Principles 3

Architecture 5


Declarative vs. Imperative 15

Visual Design Tools 18

XamlPad 18

Microsoft Expression Blend 19

Visual Designer for Windows Presentation Foundation 20

Electric Rain ZAM 3D 21

Mobiform Aurora 22

Summary 23

Chapter 2: WPF and .NET Programming 25

Getting Started 26

Required Installations 26

Types of WPF Applications 26

My First WPF Application 27

WPF Development Concepts 29


The Application Object 30

Creating the User Interface 32

Handling Events 35

Working with Controls 41

Triggers 51

Language Support 58

Deployment 61

Summary 61

Chapter 3: Anatomy of a WPF-Enabled Application 63

Project Composition 63

App.Manifest 66

AssemblyInfo.cs 66

Resources.resx 68

Settings.settings 68

MyApp.xaml 70

.NET Framework 3.0 Windows Application 71

Window1.xaml 72

XAML Browser Application 73

Page1.xaml 73

WCF Service Library 75

Class1.cs 75

WPF Custom Control Library 78

UserControl1.xaml 79

Summary 82

Chapter 4: Building a Rich UI with Microsoft Expression Blend — Part I 83

Overview 84

The Design Environment 85

Workspace Panels 86

The Artboard 87

Configuring the Environment 88

Project Structure 90

Adding a New Project File 90

Building and Deploying a Project 91

Creating Vector Objects 91

Shapes 92

Paths 93

Manipulating Objects with the Properties Panel 94

The Transform Panel 94

The Brushes Panel 95

Opacity, Transparency, and Visibility 97

Manipulating Text 98

Managing Layouts 99

UI Layout Panels 100

Other Layout Controls 103

Nesting Layout Panels 103

Animation 104

Timeline Sub-Panel 104

Keyframes 105

Animate an Object’s Property 106

Motion Paths 106

Triggers 107

Creating Controls 108

Templates 110

Styles 111

States 112

Importing Audio/Video Media 113

Summary 113

Chapter 5: Building a Rich UI with Microsoft Expression Blend — Part II 115

Expression Blend Workflow 116

Code Editing with Visual Studio 2005 117

Handling User Input 118

Keyboard and Mouse Classes 118

Events and Event Handling 118

Positioning 120

Hit Testing 124

The WPF Animation API 135

Animation Classes 135

Creating a Dynamic Animation Procedurally with Code 135

Programmatic Animation 139

Interacting with Storyboards 143

WPF Drawing API 145

Geometry 145

Shapes 146

Brushes 149

Summary 153

Chapter 6: Special Effects 155

Brushes 156

SolidColorBrush 156

GradientBrush 162

ImageBrush 165

DrawingBrush 167

VisualBrush 169

Bitmap Effects 171

Transformations 175

TranslateTransform 178

ScaleTransform 180

SkewTransform 183

RotateTransform 186

Opacity Masks 188

Putting It All Together — Combining Effects 191

Bouncing Ball with Reflection Example 191

Animated Image Viewer Example 197

Summary 203

Chapter 7: Custom Controls 205

Overview 206

Control Base Classes 207

The UserControl Class 207

Creating a User Control 207

Data Binding in WPF 217

Binding Markup Extensions 217

Binding Modes 217

Data Templates 219

Data Conversions 221

Creating and Editing Styles 222

Specifying a Style’s Target Type 223

Inheriting and Overriding Styles 224

Style Triggers 226

Customizing Existing Controls with Templates 228

Summary 231

Chapter 8: Using WPF in the Enterprise 233

WPF Application Models 234

Standalone Applications 235

Browser-Based Applications 238

Security Considerations 247

State Management 248

Application Object 248

Isolated Storage 250

State Management Example 252

Navigation 258

Elements of Navigation 258

Structured Navigation 259

Navigation Topologies 269

Application Localization 286

Automatic Layout Guidelines 287

Using Grids for Flexibility 289

Localization Attributes and Comments 290

WPF Deployment Models 291

Building Applications 292

Deploying Standalone Windows Applications 294

Deploying XAML Browser Applications 295

Deploying the .NET Framework 3.0 Runtime 296

Summary 298

Chapter 9: Security 299

WPF Security Model 299

Trusted Versus Express Applications 300

Core OS Security 300

LUA 301

Virtualization 301

Sandboxing 301

Cryptography Next Generation 302

CLR Security 302

Code Access Security 303

The Critical Code Methodology 311

Verification 313

Microsoft Internet Explorer Security 313

Zone Restrictions 313

XBAP Sandbox Workarounds 314

XAML Browser Application Security 315

ClickOnce Security 323

Trusted Publishers 323

Personal Certificate File 324

.NET 3.0 Security Utilities 327

Summary 328

Chapter 10: WPF and Win32 Interop 329

Win32 User Interface Overview 330

How WPF and HWNDs Interoperate 330

Using Win32 HWNDs Inside of WPF 331

Hosting a Win32 Button in WPF 332

Using WPF in Win32 Applications 335

Adding Windows Forms Controls to WPF 337

Adding Your WindowsFormsHost in Code 337

Adding Your HwndHost in XAML 339

Adding ActiveX Controls to WPF 339

Adding the ActiveX Control in XAML 344

Adding WPF Controls to Windows Forms 345

Affecting Control Properties 349

Summary 351

Chapter 11: Advanced Development Concepts 353

WPF Architecture 354

Core Subsystems 356

WPF Threading Model 359

Desktop Window Manager 360

The WPF Framework 361

Dispatcher Object 362

DependencyObject/DependencyProperty 362

Application 363

Freezable 364

Visual 364

UIElement 370

FrameworkElement 371

Control 371

A Deeper Look at XAML 373

XAML Under the Hood 373

Manipulating XAML On-the-Fly 378

Deconstructing Window1.xaml 382

x:Class 383

XAML Markup Extensions 385

XAML and Custom Types 386

WPF Multithreading 388

Single-Threaded Application Model 388

Thread Affinity and DispatcherObject 389

WPF Dispatcher 390

Working with Single-Threaded Applications 391

Asynchronous Threading 393

Windows Communication Foundation 397

Service Orientation 397

WCF Architecture 398

WCF Fundamentals 399

Building a WCF Service 402

Windows Workflow Foundation 409

Workflow Defined 410

WF Architecture 411

WF Fundamentals 411

Summary 427

Index 429

See More

Author Information

Chris Andrade is a Principal with Novera Consulting, a Microsoft Certified Partner specializing in enterprise architecture and development with .NET and Microsoft server technology. Chris devotes most of his time to assisting companies in applying Microsoft technologies to improve their business processes and operations. Chris has worked within a diverse range of business verticals, including automotive, healthcare, and mortgage. Chris also takes active participation within the local developer community, speaking and presenting along the west coast whenever possible.

Shawn Livermore (MCAD, MCSD, PMP) [shawnlivermore.blogspot.com] has been architecting and developing Microsoft-based solutions for nearly a decade. Shawn has been consulting as an enterprise and solutions architect for Fortune 500 clientele within highly visible enterprise implementations. His range of technical competence stretches across platforms and lines of business, but he specializes in Microsoft .NET enterprise application architectures and Microsoft server-based product integrations. Shawn lives in the Southern California area with his beautiful wife Shantell and amazing daughter Elexzandreia. Shawn also enjoys beating his friend Jason at air hockey, basketball, baseball, football, arcade games, cards, billiards, ping pong, shuffleboard, trivia, golf, racquetball, dirt bike races, crosscountry skiing... and pretty much any other sport in existence. Shawn would like to once again remind Jason, “Who’s your daddy?”

Mike Meyers is president of Novera Consulting Inc, a software development and consulting firm specializing in custom application development utilizing the .NET platform and Microsoft server technology. Based in Orange County, California, Mike’s company is focused on providing solutions based on Microsoft platforms and technology to companies spanning multiple industries. Mike has worked in a number of industries, including mortgage, healthcare, and various ecommerce ventures as developer, architect, and project manager. When he’s not writing code, Mike is active mountain biking in southern California, hiking with his four-legged Labrador Dakota or playing music with friends.

Scott Van Vliet is an accomplished Solutions Architect who has spent the past decade delivering successful Microsoft-based solutions to his clients. Currently a Senior Manager with Capgemini, a worldwide leader in technology consulting services, Scott has managed, architected, and developed solutions for companies across the globe. He is also the Microsoft Delivery Leader for Capgemini’s Telecom, Media & Entertainment practice, providing technical and engagement leadership on all Microsoft-based projects. Scott can be reached via his Web site at http://www.scottvanvliet.com/.

See More


Download TitleSizeDownload
Code Downloads
Code downloads for this title are available here.
See More
Back to Top