Programming Windows Presentation Foundation by Ian Griffiths, Chris Sells
Total Page:16
File Type:pdf, Size:1020Kb
Programming Windows Presentation Foundation By Ian Griffiths, Chris Sells ............................................... Publisher: O'Reilly Pub Date: September 2005 ISBN: 0-596-10113-9 Pages: 447 Slots: 1.0 Table of Contents | Index Windows Presentation Foundation (WPF) (formerly known by its code name "Avalon") is a brand-new presentation framework for Windows XP and Windows Vista, the next version of the Windows client operating system. For developers, WPF is a cornucopia of new technologies, including a new graphics engine that supports 3-D graphics, animation, and more; an XML-based markup language (XAML) for declaring the structure of your Windows UI; and a radical new model for controls. Programming Windows Presentation Foundation is the book you need to get up to speed on WPF. By page two, you'll have written your first WPF application, and by the end of Chapter 1, "Hello WPF," you'll have completed a rapid tour of the framework and its major elements. These include the XAML markup language and the mapping of XAML markup to WinFX code; the WPF content model; layout; controls, styles, and templates; graphics and animation; and, finally, deployment. Programming Windows Presentation Foundation features: ● Scores of C# and XAML examples that show you what it takes to get a WPF application up and running, from a simple "Hello, Avalon" program to a tic-tac-toe game ● Insightful discussions of the powerful new programming styles that WPF brings to Windows development, especially its new model for controls ● A color insert to better illustrate WPF support for 3-D, color, and other graphics effects ● A tutorial on XAML, the new HTML-like markup language for declaring Windows UI ● An explanation and comparison of the features that support interoperability with Windows Forms and other Windows legacy applications The next generation of Windows applications is going to blaze a trail into the unknown. WPF represents the best of the control-based Windows world and the content-based web world; it's an engine just itching to be taken for a spin. Inside, you'll find the keys to the ignition. Book Description Windows Presentation Foundation (WPF) (formerly known by its code name "Avalon") is a brand-new presentation framework for Windows XP and Windows Vista, the next version of the Windows client operating system. For developers, WPF is a cornucopia of new technologies, including a new graphics engine that supports 3-D graphics, animation, and more; an XML-based markup language (XAML) for declaring the structure of your Windows UI; and a radical new model for controls. Programming Windows Presentation Foundation is the book you need to get up to speed on WPF. By page two, you'll have written your first WPF application, and by the end of Chapter 1, "Hello WPF," you'll have completed a rapid tour of the framework and its major elements. These include the XAML markup language and the mapping of XAML markup to WinFX code; the WPF content model; layout; controls, styles, and templates; graphics and animation; and, finally, deployment. Programming Windows Presentation Foundation features: ● Scores of C# and XAML examples that show you what it takes to get a WPF application up and running, from a simple "Hello, Avalon" program to a tic-tac-toe game ● Insightful discussions of the powerful new programming styles that WPF brings to Windows development, especially its new model for controls ● A color insert to better illustrate WPF support for 3-D, color, and other graphics effects ● A tutorial on XAML, the new HTML-like markup language for declaring Windows UI ● An explanation and comparison of the features that support interoperability with Windows Forms and other Windows legacy applications The next generation of Windows applications is going to blaze a trail into the unknown. WPF represents the best of the control-based Windows world and the content-based web world; it's an engine just itching to be taken for a spin. Inside, you'll find the keys to the ignition. Programming Windows Presentation Foundation by Chris Sells and Ian Griffiths Copyright © 2005 O'Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: John Osborn Development Editor: Michael Weinhardt Production Editor: Sanders Kleinfeld Cover Designer: Ellie Volckhausen Interior Designer: David Futato Printing History: September 2005: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. Programming Windows Presentation Foundation, the image of a kudu, and related trade dress are trademarks of O'Reilly Media, Inc. Microsoft, the .NET logo, Visual Basic .NET, Visual Studio .NET, ADO.NET, Windows, and Windows 2000 are registered trademarks of Microsoft Corporation. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 0-596-10113-9 [C] Copyright Preface Who This Book Is For How This Book Is Organized What You Need to Use This Book Conventions Used in This Book Using Code Examples Safari® Enabled How to Contact Us Ian's Acknowledgments Chris's Acknowledgments Chapter 1. Hello, WPF Section 1.1. WPF from Scratch Section 1.2. Navigation Applications Section 1.3. Content Model Section 1.4. Layout Section 1.5. Controls Section 1.6. Data Binding Section 1.7. Dependency Properties Section 1.8. Resources Section 1.9. Styles and Control Templates Section 1.10. Graphics Section 1.11. Application Deployment Section 1.12. Where Are We? Chapter 2. Layout Section 2.1. Layout Basics Section 2.2. DockPanel Section 2.3. StackPanel Section 2.4. Grid Section 2.5. Canvas Section 2.6. Viewbox Section 2.7. Text Layout Section 2.8. Common Layout Properties Section 2.9. When Content Doesn't Fit Section 2.10. Custom Layout Section 2.11. Where Are We? Chapter 3. Controls Section 3.1. What Are Controls? Section 3.2. Handling Input Section 3.3. Built-In Controls Section 3.4. Where Are We? Chapter 4. Data Binding Section 4.1. Without Data Binding Section 4.2. Data Binding Section 4.3. Binding to List Data Section 4.4. Data Sources Section 4.5. Master-Detail Binding Section 4.6. Where Are We? Chapter 5. Styles and Control Templates Section 5.1. Without Styles Section 5.2. Inline Styles Section 5.3. Named Styles Section 5.4. Element-Typed Styles Section 5.5. Data Templates and Styles Section 5.6. Triggers Section 5.7. Control Templates Section 5.8. Where Are We? Chapter 6. Resources Section 6.1. Creating and Using Resources Section 6.2. Resources and Styles Section 6.3. Binary Resources Section 6.4. Global Applications Section 6.5. Where Are We? Chapter 7. Graphics Section 7.1. Graphics Fundamentals Section 7.2. Shapes Section 7.3. Brushes and Pens Section 7.4. Transformations Section 7.5. Visual-Layer Programming Section 7.6. Video and 3-D Section 7.7. Where Are We? Chapter 8. Animation Section 8.1. Animation Fundamentals Section 8.2. Timelines Section 8.3. Storyboards Section 8.4. Key Frame Animations Section 8.5. Creating Animations Procedurally Section 8.6. Where Are We? Chapter 9. Custom Controls Section 9.1. Custom Control Basics Section 9.2. Choosing a Base Class Section 9.3. Custom Functionality Section 9.4. Templates Section 9.5. Default Visuals Section 9.6. Where Are We? Chapter 10. ClickOnce Deployment Section 10.1. A Brief History of Windows Deployment Section 10.2. ClickOnce: Local Install Section 10.3. The Pieces of ClickOnce Section 10.4. Publish Properties Section 10.5. Deploying Updates Section 10.6. ClickOnce: Express Applications Section 10.7. Choosing Local Install versus Express Section 10.8. Signing ClickOnce Applications Section 10.9. Programming for ClickOnce Section 10.10. Security Considerations Section 10.11. Where Are We? Appendix A. XAML Section A.1. XAML Essentials Section A.2. Properties Section A.3. Markup Extensions Section A.4. Code-Behind Section A.5. Using Custom Types Section A.6. Common Child-Content Patterns Section A.7. Loading XAML Appendix B. Interoperability Section B.1. WPF and HWNDs Section B.2. Hosting a Windows Form Control in WPF Section B.3. Hosting a WPF Control in Windows Forms Section B.4. Hosting WPF in Native HWND Apps Section B.5. WPF and ActiveX Controls Section B.6. WPF and HTML Appendix C. Asynchronous and Multithreaded Programming in WPF Applications Section C.1. The WPF Threading Model Section C.2. The Dispatcher Section C.3. BackgroundWorker Color Plates About the Authors Colophon Index Preface It's been a long road to Windows Presentation Foundation, better known to many as Avalon, the in-house Microsoft code name for the new Windows Vista presentation framework. I learned to program Windows from Programming Windows 3.1 by Charles Petzold (Microsoft Press). In those days, programming for Windows was about windows, menus, dialogs and child controls. To make it all work, we had WndProcs (windows procedure functions) and messages. We dealt with the keyboard and the mouse.