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

Overview

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 ...

See more details below
Paperback (Workbook)
$35.54
BN.com price
(Save 28%)$49.99 List Price
Other sellers (Paperback)
  • All (13) from $3.90   
  • New (5) from $23.98   
  • Used (8) from $3.90   
Sending request ...

Overview

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®. Next you'll discover how to build more sophisticated WPF interfaces using Microsoft® 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® 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.

Read More Show Less

Product Details

  • ISBN-13: 9780470041802
  • Publisher: Wiley
  • Publication date: 4/16/2007
  • Series: Wrox Professional Guides
  • Edition description: Workbook
  • Edition number: 1
  • Pages: 480
  • Product dimensions: 7.30 (w) x 9.20 (h) x 1.00 (d)

Read an Excerpt

Professional WPF Programming

.NET Development with the Windows Presentation Foundation
By Chris Andrade Shawn Livermore Mike Meyers Scott Van Vliet

John Wiley & Sons

Copyright © 2007 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-0-470-04180-2


Chapter One

Overview of Windows Presentation Foundation

For those of us who have been developing applications to run on the Windows platform, the topic of this book presents a compelling and exciting wave of change to how such applications can be built. In addition, for those of us who have been developing web-based applications, an even more exciting shift is approaching.

Windows Presentation Foundation, also known as WPF, is the next-generation graphics platform on which both Windows- and web-based applications can be built to run on Windows Vista, the latest evolutionary release of the Windows operating system. WPF provides the foundation for introducing an elegant and high fidelity User Experience (UX) by juxtaposition of user interface, application logic, documents, and media content.

Although originally targeted solely for Windows Vista, WPF will be made available for Windows XP and Windows Server 2003 as part of the .NET Framework 3.0 (formerly WinFX) developerplatform.

This coalescence of form and function is further empowered by tools such as XAML and the Microsoft Expression Designers, which allow designers and developers to work in parallel on the user interface and the application logic, coming together to provide a seamless UX.

This chapter provides an overview of WPF, including the following key topics:

Evolution of the Windows API

.NET Framework 3.0, the next-generation APIs for Windows-based development

WPF architecture and development model

XAML, the new declarative language backing WPF

Tools to develop WPF applications

A Brief History of the Windows API

The Windows API exposes the core set of functionality provided by the Windows operating system for use in applications. Primarily designed for C/C++ development, the Windows API has been the most direct mechanism with which an application can interact with Windows.

The Windows API comprises the following functional groups:

Base Services - Provides access to the core resources of the computer, such as memory, filesystems, devices, processes, and threads

Common Control Library - A collection of common control windows used throughout the Windows operating system, providing the distinctive Windows look and feel

Common Dialog Box Library - A collection of dialog boxes used to execute common tasks, including file opening, saving, and printing

Graphics Device Interface (GDI) - Provides the facilities for an application to generate graphical output to displays, printers, and other devices

Network Services - Provides access to various networking capabilities of the Windows operating system, including RPC and NetBIOS

User Interface (UI) - Provides the mechanism for managing windows and controls in an application and input from devices such as the mouse and keyboard

Windows Shell - The container that organizes and presents the entire Windows UI, including the desktop, taskbar, and Windows Explorer

Through these services, developers have had significant flexibility in creating powerful applications for the Windows operating system. However, this flexibility also bore the responsibility of handling low-level and often tedious operations.

With each new release of the Windows operating system, additions and updates to the Windows API were almost always included. Yet with each release, Microsoft strived to support backwards compatibility. Thus, many functions included in the original Windows API still exist today in Windows XP and Windows Server 2003.

The following list includes major versions of the Windows API:

Win16 - The API for the first 16-bit versions of Windows

Win32 - Introduced in Windows NT, the API for 32-bit versions of Windows

Win32 for 64-bit Windows - Formerly known as Win64, the API for 64-bit versions of Windows XP and Windows Server 2003

Platform Evolution

Since the release of Windows 1.0 more than 20 years ago, the GDI and the UI services of the Windows API have provided a reliable graphics platform for Windows applications. Many applications we use on a day-to-day basis, including the Microsoft Office suite and Internet Explorer, are built on this foundation.

Although this graphics platform has seen many successes, fundamental changes have occurred in technology since its initial appearance more than two decades ago. With the proliferation of the personal computer and the increasing availability of broadband Internet access, the demand for rich visual experiences has dramatically increased. Moreover, advancements in graphics hardware technology have paved the way for astounding digital media and interactive entertainment products. Facing this new demand for a rich visual experience, Microsoft has invested heavily in providing such an experience as part of the next-generation Windows API - .NET Framework 3.0.

Introducing .NET Framework 3.0

.NET Framework 3.0 is a revolutionary milestone for developing applications on the Windows operating system. Built atop the .NET Framework 2.0, .NET Framework 3.0 is a set of managed APIs that provide enhanced functionality for messaging, workflow, and presentation.

Key components of .NET Framework 3.0 include:

Windows Presentation Foundation (WPF) - The graphical subsystem for all things related to the UI

Windows Communication Foundation (WCF) - The messaging subsystem of .NET Framework 3.0, securing program communication through a single API

Windows Workflow Foundation (WF) - Provides workflow services for applications built to run on Windows

As the new programming model for Windows Vista, .NET Framework 3.0 fuses the Windows platform with applications developed using Visual Studio 2005. With direct access to low-level services of the operating system and hardware surface, .NET Framework 3.0 provides a compelling solution for creating applications with a rich UX.

Although WCF and WF are equally important components of .NET Framework 3.0, they are beyond the scope of this book. For more information on WCF and WF, visit the .NET Framework Developer Center on MSDN (http://msdn2.microsoft.com/en-us/netframework).

Meet Windows Presentation Foundation

Formerly known as Avalon, Windows Presentation Foundation (WPF) is the new graphical subsystem in Windows Vista that provides a holistic means for combining user interface, 2D and 3D graphics, documents, and digital media. Built on the .NET Framework, WPF provides a managed environment for development with the Windows operating system. This takes advantage of the existing investment made by Microsoft in the .NET Framework, and allows developers familiar with .NET technologies to rapidly begin developing applications that leverage WPF.

Guiding Design Principles

To enhance UX and empower both designers and developers, WPF has been built under the following design principles:

Integration

Vector graphics

Declarative programming

Simplified deployment

Document portability

Integration

In today's world, developing a Windows application may require the use of any number of different technologies, ranging from GDI/GDI+ for 2D graphics, UI services (User32 or WinForms), or Direct3D or OpenGL for 3D graphics. On the contrary, WPF was designed as a single model for application development, providing seamless integration between such services within an application. Similar constructs can be used for developing storyboard animation, data bound forms, and 3D models.

Vector Graphics

To take advantage of new powerful graphics hardware, WPF implements a vector-based composition engine. This allows for graphics to scale based on screen-specific resolution without loss of quality, something nearly impossible with fixed-size raster graphics. WPF leverages Direct3D for vector-based rendering, and will utilize the graphics processing unit (GPU) on any video card implementing DirectX 7 or later in hardware. In anticipation of future technology, such as high-resolution displays and unknown form factors, WPF implements a floating-point logical pixel system and supports 32-bit ARGB colors.

Declarative Programming

WPF introduces a new XML-based language to represent UI and user interaction, known as XAML (eXtensible Application Markup Language - pronounced "zammel"). Similar to Macromedia's MXML specification, within XAML elements from the UI are represented as XML tags. Thus, XAML allows applications to dynamically parse and manipulate UI elements at either compile-time or runtime, providing a flexible model for UI composition.

Following the success of ASP.NET, XAML follows the code-behind model, allowing designers and developers to work in parallel and seamlessly combine their work to create a compelling UX. With the aid of design-time tools such as the Visual Designer for Windows Presentation Foundation add-in for Visual Studio 2005, the experience of developing XAML-based applications resembles that of WinForms development. Moreover, designers accustomed to visual tools such as Macromedia Flash 8 Professional can quickly ramp-up to building XAML-based solutions using visual design tools such as Microsoft Expression Blend. These tools are covered later in this chapter and throughout this book.

Simplified Deployment

WPF applications can be deployed as standalone applications or as web-based applications hosted in Internet Explorer. As with smart client applications, web-based WPF applications operate in a partial-trust sandbox, which protects the client computer against applications with malicious purpose.

Furthermore, WPF applications hosted in Internet Explorer can exploit the capabilities of local client hardware, providing a rich web experience with 3D, digital media, and more, which is the best argument for web-based applications available today.

Document Portability

Included in WPF is an exciting new set of document and printing technologies. In conjunction with the release of Microsoft Office 12, WPF utilizes Open Packaging Conventions, which supports compression, custom metadata, digital signatures, and rights management. Similar to the Portable Document Format (PDF), the XML Paper Specification (XPS), which allows for documents to be shared across computers without requiring that the originating application be installed, is included in WPF.

Architecture

The anatomy of WPF consists of unmanaged services, managed subsystems, and a managed API available for consumption by WPF applications, known as the presentation framework.

Figure 1-1 outlines the general underlying architecture of WPF, with each major component detailed in the sections that follow.

Element System

The element system represents the surface of WPF with which developers will interact. Contained within the element system are the core components making up the UI, such as styles, layout, controls, binding, and text layout.

Almost all the components in the element system derive from the all-important System.Windows .FrameworkElement class. This class provides the base functionality required to interact with WPF core presentation service, and implements key members of its parent class, System.Windows.UIElement, which provides functionality for all visual elements within WPF for layout, eventing, and input. The UIElement class can be compared to HWND in Win32, and is the starting point for input-specific functionality within the WPF inheritance hierarchy. The FrameworkElement and related classes are discussed further in Chapter 2.

Most of the topics covered within this book related to WPF application development pertain to components and features of the element system. However, the underlying subsystems are indeed used extensively by WPF applications, and will be noted where appropriate.

Element Trees

An important concept to grasp in WPF is the notion of element trees, which represent the visual elements of which a WPF application is comprised. Two element trees exist within a WPF application: the logical tree and the visual tree.

Logical Tree

The logical tree is the hierarchical structure containing the exact elements of your WPF application as defined either declaratively within a XAML file, or imperatively in code. Consider the following XAML code snippet:

When compiled for or parsed under WPF, this code snippet would yield a logical tree like that depicted in Figure 1-2.

The logical tree outlines the 1:1 mapping of the nested XAML elements declared in the code snippet to their appropriate classes in the WPF API. The top-level element is ElementTrees.Sample, which derives from System.Windows.Window, the top-most, non-navigable container for a WPF application.

The Window class itself derives from System.Windows.Controls.ContentControl, which is the base class for all controls containing a single piece of content within WPF. To provide support for context-aware layout, the System.Windows.Controls.Panel class is available and includes functionality to arrange and lay out elements in WPF. The next element in the logical tree for the preceding code snippet is System.Windows.Controls.StackPanel, which derives from Panel. StackPanel arranges all client elements of the control in a single line, oriented either horizontally or vertically. This control behaves similarly to an HTML table with a single column or row, depending on orientation.

Contained within the StackPanel instance are the controls visible to the user: System.Windows.Controls.TextBox, System.Windows.Controls.Button, and System.Windows.Controls.Label. Although ubiquitous, these controls are unique implementations created from the ground up for WPF. Although they may behave in much the same way as their counterparts in WinForms from a user's perspective, their composition and behavior within the programming model and the visual tree are quite different.

Visual Tree

As its name implies, the logical tree makes sense - each element in the application is represented by a corresponding instance created by WPF. Under the hood, however, much more is taking place.

For each element in the logical tree, additional elements may be created to represent visual aspects required by the element. The combination of application elements and the elements created for visualization support is known as the visual tree. Considering the previous code snippet, the visual tree shown in Figure 1-3 would result.

Okay, take a moment to catch your breath. WPF does a lot of work under the hood to support the flexible visual model implemented therein. In addition to the elements of the application included in the logical tree, 20 additional elements are created to support visualization. The following are some of these elements created for the ElementTrees.Sample element:

System.Windows.Controls.Border - This control will draw a border and/or background surrounding its nested elements. The Border control is commonly found in many default controls, such as System.Windows.Controls.Canvas, System.Windows.Controls.Label, and System.Windows.Controls.TextBox.

System.Windows.Controls.Grid - Similar to an HTML table, the Grid control provides a flexible area for content layout and positioning using rows and columns. Note, however, that there is a distinct Table control, System.Windows.Documents.Table, which provides block-level content flow also based on rows and columns and derives from a different class than Grid, which derives from System.Windows.Controls.Panel.

(Continues...)



Excerpted from Professional WPF Programming by Chris Andrade Shawn Livermore Mike Meyers Scott Van Vliet Copyright © 2007 by John Wiley & Sons, Ltd. Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)