ebook img

Pro WPF with VB 2008 Windows Presentation Foundation with dot NET 3.5 PDF

1089 Pages·2008·14.28 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Pro WPF with VB 2008 Windows Presentation Foundation with dot NET 3.5

cyan yelloW MaGenTa Black panTone 123 c Books for professionals By professionals® The eXperT’s Voice® in .neT Companion eBook Available Pro WPF with VB 2008: Pro Windows Presentation Foundation with .NET 3.5 Pro Dear Reader, For years, .NET developers have created Windows applications with the W Windows Forms toolkit. And though Windows Forms is mature and reasonably WPF full-featured, it’s hardwired to essential bits of Windows plumbing that haven’t changed much in the past ten years. As a result, some tasks that should be easy Author of require a lot of work. P Pro WPF in C# 2008: The Windows Presentation Foundation (WPF) changes all this by introduc- with Windows Presentation ing a new model with entirely different plumbing. Although WPF includes the Foundation with .NET 3.5 standard controls you’re familiar with, it draws every detail itself, using the F Pro .NET 2.0 Windows high-performance DirectX engine. As a result, WPF can provide a whole host Forms and Custom Controls of eye-popping new features, all of which we’ll cover in this book. For example, in VB 2005 we’ll give common controls like buttons a slick, customized look without writing w VB 2008 The Book of Visual Basic a line of code. Similarly, we will craft animated effects that rotate, stretch, scale, 2005 and skew anything in your user interface right before the user’s eyes. Tasks that would have been difficult or nearly impossible in Windows Forms—such as Coauthor of i playing media files or creating texture-mapped 3-D shapes—are finally possible. t Pro ASP.NET 3.5 in C# 2008 By the time you’ve finished this book, you’ll have mastered these previously (with Mario Szpuszta) h tough tasks. Although WPF’s video, animation, and 3-D features get the most hype, WPF is just as useful for building business applications that don’t need rich graphics. V We’ll cover WPF’s enhancements of key business features such as data binding, print management, and document display, giving you all you need to create professional business applications in WPF. B Windows Presentation Foundation with .NET 3.5 Welcome aboard! Matthew MacDonald (Microsoft MVP, MCSD) 2 Companion eBook THE APRESS ROADMAP Create the next generation of Windows applications. 0 Pro VB 2008 and the Beginning VB 2008 Beginning VB 2008 .NET 3.5 Platform, Databases Third Edition Pro WPF 0 See last page for details with VB 2008 on $10 eBook version Accelerated VB 2008 Beginning ASP.NET 3.5 Visual Basic 2008 in VB 2008 Recipes 8 Matthew MacDonald SOURCE CODE ONLINE ISBN-13: 978-1-59059-962-4 www.apress.com ISBN-10: 1-59059-962-4 55499 MacDonald US $54.99 Shelve in Programming/Microsoft/.NET User level: 9 781590 599624 Intermediate–Advanced this print for content only—size & color not accurate spine = 2.035" 1,088 page count 962-4 FM.qxd 3/6/08 10:54 AM Page i Pro WPF with VB 2008 Windows Presentation Foundation with .NET 3.5 Matthew MacDonald 962-4 FM.qxd 3/6/08 10:54 AM Page ii Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5 Copyright © 2008 by Matthew MacDonald All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-962-4 ISBN-10 (pbk): 1-59059- 962-4 ISBN-13 (electronic): 978-1-4302-0590-6 ISBN-10 (electronic): 1-4302-0590-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Matt Moodie Technical Reviewer: Christophe Nasarre Editorial Board: Clay Andres, Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Kevin Goff, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Sofia Marchant Copy Editor: Kim Wimpsett Associate Production Director: Kari Brooks-Copony Production Editor: Laura Esterman Compositor: Gina Rexrode Proofreader: Liz Welch Indexer: Broccoli Information Management Artists: Diana Van Winkle, April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com. 962-4 FM.qxd 3/6/08 10:54 AM Page iii For my wonderful family, Faria and Maya 962-4 FM.qxd 3/6/08 10:54 AM Page iv Contents at a Glance About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix nCHAPTER 1 Introducing WPF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 nCHAPTER 2 XAML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 nCHAPTER 3 The Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 nCHAPTER 4 Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 nCHAPTER 5 Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 nCHAPTER 6 Dependency Properties and Routed Events. . . . . . . . . . . . . . . . . . . . 139 nCHAPTER 7 Classic Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 nCHAPTER 8 Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 nCHAPTER 9 Pages and Navigation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 nCHAPTER 10 Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 nCHAPTER 11 Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 nCHAPTER 12 Styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 nCHAPTER 13 Shapes,Transforms,and Brushes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 nCHAPTER 14 Geometries,Drawings,and Visuals. . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 nCHAPTER 15 Control Templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 nCHAPTER 16 Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 nCHAPTER 17 Data Templates,Data Views,and Data Providers . . . . . . . . . . . . . . 561 nCHAPTER 18 Lists,Trees,Toolbars,and Menus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609 nCHAPTER 19 Documents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655 nCHAPTER 20 Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 nCHAPTER 21 Animation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741 nCHAPTER 22 Sound and Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795 nCHAPTER 23 3-D Drawing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821 iv 962-4 FM.qxd 3/6/08 10:54 AM Page v nCHAPTER 24 Custom Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867 nCHAPTER 25 Interacting with Windows Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917 nCHAPTER 26 Multithreading and Add-Ins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941 nCHAPTER 27 ClickOnce Deployment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979 nINDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997 v 962-4 FM.qxd 3/6/08 10:54 AM Page vi 962-4 FM.qxd 3/6/08 10:54 AM Page vii Contents About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix nCHAPTER 1 Introducing WPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Understanding Windows Graphics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 DirectX:The New Graphics Engine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Hardware Acceleration and WPF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 WPF:A Higher-Level API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Resolution Independence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 The Evolution of WPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Windows Forms Lives On. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 DirectX Also Lives On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Silverlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 The Architecture of WPF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 The Class Hierarchy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 The Last Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 nCHAPTER 2 XAML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Understanding XAML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Graphical User Interfaces Before WPF. . . . . . . . . . . . . . . . . . . . . . . . . 24 The Variants of XAML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 XAML Compilation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 XAML Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 XAML Namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 The Code-Behind Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Properties and Events in XAML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Simple Properties and Type Converters. . . . . . . . . . . . . . . . . . . . . . . . 33 Complex Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Markup Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Attached Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Nesting Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 vii 962-4 FM.qxd 3/6/08 10:54 AM Page viii viii nCONTENTS Special Characters and Whitespace. . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 The Full Eight Ball Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Using Types from Other Namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Loading and Compiling XAML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Code-Only. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Code and Uncompiled XAML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Code and Compiled XAML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 XAML Only. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 The Last Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 nCHAPTER 3 The Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 The Application Life Cycle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Creating an Application Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Deriving a Custom Application Class. . . . . . . . . . . . . . . . . . . . . . . . . . 60 Application Shutdown. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Application Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Application Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Handling Command-Line Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . 65 Accessing the Current Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Interacting Between Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Single-Instance Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 The Last Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 nCHAPTER 4 Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Understanding Layout in WPF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 The WPF Layout Philosophy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 The Layout Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 The Layout Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Simple Layout with the StackPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Layout Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Margin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Minimum,Maximum,and Explicit Sizes . . . . . . . . . . . . . . . . . . . . . . . 86 The WrapPanel and DockPanel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 The WrapPanel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 The DockPanel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Nesting Layout Containers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

Description:
Microsoft Windows Presentation Foundation provides the foundation for building applications and high–quality user experiences in Windows Vista. WPF blends application user interface, documents, and media content to provide richer control, design, and development of the visual aspects of Windows pr
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.