1. Trang chủ
  2. » Công Nghệ Thông Tin

programming WPF phần 1 potx

88 407 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 88
Dung lượng 2,57 MB

Nội dung

Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Programming WPF SECOND EDITION Chris Sells and Ian Griffiths Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Programming WPF, Second Edition by Chris Sells and Ian Griffiths Copyright © 2007, 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 corporate@oreilly.com. Editor: John Osborn Production Editor: Rachel Monaghan Copyeditor: Audrey Doyle Proofreader: Rachel Monaghan Indexer: John Bickelhaupt Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrators: Robert Romano and Jessamyn Read Printing History: August 2007: Second Edition. September 2005: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Programming WPF, the image of a kudu, and related trade dress are trademarks of O’Reilly Media, Inc. 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 authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. This book uses RepKover ™ , a durable and flexible lay-flat binding. ISBN-10: 0-596-51037-3 ISBN-13: 978-0-596-51037-4 [C] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Abi: Thank you for everything. My parents: Thank you for making it all possible. —Ian Griffiths My wife and my sons: You define the heaven that exceeds my grasp. Both my parents: You made me love reading from the beginning. I was happy that you passed on the secret writer gene (not to mention surprised). —Chris Sells Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com v Table of Contents Forewords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv 1. Hello, WPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 WPF from Scratch 1 XAML Browser Applications (XBAPs) 14 Content Models 16 Layout 19 Controls 22 Data Binding 22 Dependency Properties 27 Resources 28 Styles 30 Animation 31 Control Templates 32 Graphics 33 3D 34 Documents and Printing 34 2. Applications and Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Application Lifetime 36 Application Deployment 48 Settings 55 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com vi | Table of Contents 3. Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Layout Basics 61 StackPanel 62 WrapPanel 65 DockPanel 66 Grid 69 Canvas 84 Viewbox 86 Common Layout Properties 89 When Content Doesn’t Fit 99 ScrollViewer 101 Custom Layout 105 4. Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Routed Events 109 Mouse Input 117 Keyboard Input 120 Ink Input 122 Commands 124 Code-Based Input Handling Versus Triggers 137 5. Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 What Are Controls? 139 Buttons 141 Slider and Scroll Controls 144 ProgressBar 145 Text Controls 146 ToolTip 149 GroupBox and Expander 150 List Controls 152 Menus 160 Toolbars 164 GridSplitter 166 6. Simple Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Without Data Binding 168 Data Binding 177 Debugging Data Binding 198 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Table of Contents | vii 7. Binding to List Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Binding to List Data 200 Data Source Providers 228 Master-Detail Binding 245 Hierarchical Binding 252 8. Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Without Styles 257 Inline Styles 261 Named Styles 262 Element-Typed Styles 268 Data Templates and Styles 271 Triggers 275 9. Control Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 Beyond Styles 284 Logical and Visual Trees 305 Data-Driven UI 308 10. Windows and Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Window 314 Dialogs 322 11. Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 NavigationWindow 341 Pages 342 Frames 359 XBAPs 361 Navigation to HTML 363 12. Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 Creating and Using Resources 365 Resources and Styles 378 Binary Resources 383 Global Applications 389 13. Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Graphics Fundamentals 395 Shapes 406 Bitmaps 429 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com viii | Table of Contents Brushes and Pens 439 Transformations 461 Visual Layer Programming 463 14. Text and Flow Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 Fonts and Text Styles 468 Text and the User Interface 478 Text Object Model 493 Typography 519 15. Printing and XPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522 XPS 522 XPS Document Classes 524 Generating XPS Output 533 XPS File Generation Features 543 System.Printing 555 Displaying Fixed Documents 561 16. Animation and Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 Animation Fundamentals 563 Timelines 579 Keyframe Animations 593 Path Animations 598 Clocks and Control 601 Transition Animations 605 Audio and Video 608 17. 3D Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612 3D Content in a 2D World 612 Cameras 613 Models 618 Lights 629 Textures 635 Transforms 637 3D Data Visualization 642 Hit Testing 648 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Table of Contents | ix 18. Custom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651 Custom Control Basics 651 Choosing a Base Class 652 Custom Functionality 655 Supporting Templates in Custom Controls 668 Default Styles 674 UserControl 676 Adorners 678 A. XAML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683 B. Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 C. Asynchronous and Multithreaded WPF Programming . . . . . . . . . . . . . . . . . 738 D. WPF Base Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750 E. Silverlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... Microsoft’s WPF community site: http:/ /wpf. netfx3.com • The MSDN WPF home page: http://msdn2.microsoft.com/en-us/netframework/ aa663326.aspx (http://tinysells.com /11 7) • CodeProject’s WPF section: http://www.codeproject.com /WPF (http://tinysells.com/ 11 8) • thirteen23’s inspirational set of WPF lab experiments: http://www.thirteen23.com/ labs.html (http://tinysells.com /11 9) • Lee Brimelow’s set of WPF designer... great WPF applications: http://blogs.msdn.com/tims/ search.aspx?q=%22great +wpf+ applications%22 (http://tinysells.com /11 4) • Tim Sneath’s big list of WPF blogs: http://blogs.msdn.com/tims/articles/47 513 2.aspx (http://tinysells.com /11 5) • Karsten Januszewski’s Five-Day Course for Hitting the WPF Curve/Cliff: http:// blogs.msdn.com/karstenj/archive/2006/06 /15 /632639.aspx (http://tinysells.com /11 6) • Microsoft’s... in detail in the chapters that follow WPF from Scratch Example 1- 1 is pretty much the smallest WPF “application” you can write in C# Example 1- 1 Minimal C# WPF application // MyApp.cs using System; using System.Windows; // the root WPF namespace namespace MyFirstWpfApp { class MyApp { [STAThread] static void Main( ) { // the WPF message box MessageBox.Show("Hello, WPF" ); } } } The STAThread attribute... compiling the MyApp.cs source file Running the resulting 1st.exe produces the world’s lamest WPF application, as shown in Figure 1- 1 Figure 1- 1 A lame WPF application * Start ➝ All Programs ➝ Microsoft Windows SDK ➝ CMD Shell 2 | Chapter 1: Hello, WPF Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com In anticipation of less lame WPF applications with more source files and more compilation... Copying file from "obj\Debug\1st.exe" to ".\1st.exe" 1st -> C:\1st\1st.exe Copying file from "obj\Debug\1st.pdb" to ".\1st.pdb" Build succeeded 0 Warning(s) 0 Error(s) Time Elapsed 00:00:04 .15 As I mentioned, msbuild and Visual Studio 2005 share a project file format, so loading the project file into Visual Studio is as easy as double-clicking on 1st.csproj (as shown in Figure 1- 2) Unfortunately, as nice... one for WPF (which we’ve declared as the default for this XML file) You can think of the XAML in Example 1- 8 as creating the partial class definition in Example 1- 9 Example 1- 9 C# equivalent of XAML from Example 1- 8 namespace MyFirstWpfApp { partial class Window1 : Window { Button button; 8 | Chapter 1: Hello, WPF Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Example 1- 9 C#... not defined in the XAML With the XAML from Example 1- 8 in place, we can reduce our single-buttoned main window code-behind file to the code in Example 1- 10 Example 1- 10 C# code-behind file // Window1.xaml.cs using System; using System.Windows; using System.Windows.Controls; namespace MyFirstWpfApp { public partial class Window1 : Window { public Window1( ) { InitializeComponent( ); } void button_Click(object... abstracting) to create custom classes for such things, like the Window1 class (Example 1- 6) Example 1- 6 Window class declaring its own controls // Window1.cs using System; using System.Windows; using System.Windows.Controls; // Button et al namespace MyFirstWpfApp { class Window1 : Window { public Window1( ) { this.Title = "Hello, WPF" ; // Do something interesting (sorta ) Button button = new Button(... base for custom application-wide data and behavior (Example 1- 5) 4 | Chapter 1: Hello, WPF Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Figure 1- 2 Loading the minimal msbuild project file into Visual Studio Example 1- 5 A less minimal WPF application // MyApp.cs using System; using System.Windows; namespace MyFirstWpfApp { class MyApp : Application { [STAThread] static void... a WPF application to be hosted in a web browser Chapter 12 , Resources This chapter describes WPF s resource handling mechanisms, which are used for managing styles, themes, and binary resources such as graphics Chapter 13 , Graphics WPF offers a powerful set of drawing primitives It also offers an object model for manipulating drawings once you have created them Chapter 14 , Text and Flow Documents WPF . . . . 13 9 What Are Controls? 13 9 Buttons 14 1 Slider and Scroll Controls 14 4 ProgressBar 14 5 Text Controls 14 6 ToolTip 14 9 GroupBox and Expander 15 0 List Controls 15 2 Menus 16 0 Toolbars 16 4 GridSplitter. . . . . . . . . . . . . . . . . 10 9 Routed Events 10 9 Mouse Input 11 7 Keyboard Input 12 0 Ink Input 12 2 Commands 12 4 Code-Based Input Handling Versus Triggers 13 7 5. Controls . . . . . . . (http://tinysells.com /11 6) • Microsoft’s WPF community site: http:/ /wpf. netfx3.com • The MSDN WPF home page: http://msdn2.microsoft.com/en-us/netframework/ aa663326.aspx (http://tinysells.com /11 7) • CodeProject’s

Ngày đăng: 13/08/2014, 08:20

TỪ KHÓA LIÊN QUAN