Table of Contents Chapter 1 Getting Started with Windows Presentation Foundation 1 Exploring the New Features of WPF 4.0... 2 New WPF Controls for Business Applications... 3 Enhanced Support for WPF and Silverlight Applications... 3 Support for Touch-Enabled Applications... 3 Support for Easing Functions to Enhance Animations... 3 VSM to Enhance Controls Appearances... 4 Selection and Caret Brushes to Change Color... 4 Enhanced Support for WPF Text Rendering Stack... 4 Enhanced XBAPs... 5 Exploring the WPF 4.0 Architecture... 5 The PresentationFramework Component... 6 The PresentationCore Component... 6 The WindowsBase Component... 6 MIL or Milcore... 6 Exploring WPF 4.0 Class Hierarchy... 6 The System.Windows.Threading.DispatcherObject Class... 7 The System.Windows.DependencyObject Class... 8 The System.Windows.Freezable Class... 8 The System.Windows.Media.Visual Class... 8 The System.Windows.UIElement Class... 9 The System.Windows.FrameworkElement Class... 9 Exploring the WPF 4.0 Application Model... 10 The Application Class... 10 Types of WPF Applications... 11 Exploring the WPF 4.0 Designer... 17 Solution Explorer... 18 The Properties Window... 18 The Toolbox... 19 The Design View... 19 The XAML View... 22 The Split View Bar... 22 The Tag Navigator... 23 iii
WPF 4.0 in Simple Steps The Document Outline Window... 25 Compiling and Executing WPF 4.0 Applications... 25 Summary... 26 Chapter 2 Working with XAML in WPF 27 Exploring the XAML Element Tree... 28 Exploring XAML Object Elements... 29 Creating XAML Elements in the XAML View... 29 Creating XAML Elements in the Code-Behind File... 31 Exploring XAML Attributes... 32 Setting Properties Through the Attribute Syntax... 32 Setting Properties Through the Property Element Syntax... 33 Exploring XAML Namespaces... 33 Exploring Markup Extensions... 35 Summary... 36 Chapter 3 Working with WPF Controls and Dialog Boxes 37 Exploring WPF 4.0 Controls... 38 Container Controls... 38 Simple Controls... 45 Content Controls... 53 HeaderedContent Controls... 59 Items Controls... 61 HeaderedItems Controls... 65 Date Display and Selection Controls... 68 Data Display Controls... 71 Miscellaneous Controls... 75 Exploring Dialog boxes in WPF... 79 MessageBox... 79 SaveFile... 81 OpenFile... 83 Print... 85 Exploring Interoperability between Windows Forms and WPF 4.0... 88 Hosting a Windows Forms Control in a WPF Application... 89 Hosting a WPF Control in a Windows Forms Application... 90 Summary... 92 iv
Table of Contents Chapter 4 Working with Dependency Properties and Routed Events in WPF 93 Exploring Dependency Properties... 94 The DependencyProperty Class... 95 Property Value Inheritance... 96 Precedence of Dependency Property Values... 96 Callbacks for Dependency Properties... 99 Dependency Property Metadata... 101 Custom Dependency Properties... 102 Exploring Attached Properties... 107 Exploring Routed Events... 111 Handlers for Routed Events... 112 Routing Strategies... 113 Custom Routed Events... 117 Exploring Attached Events... 121 Exploring Lifetime Events... 122 Application Lifetime Events... 123 Window Lifetime Events... 123 Summary... 124 Chapter 5 Working with WPF Resources, Styles, Templates, Triggers, and Commands 125 Exploring WPF Resources... 126 Working with Static Resources... 127 Working with Dynamic Resources... 128 Exploring Styles in WPF... 130 Setting Styles through Resources... 131 Extending an Existing Style... 132 Exploring Templates in WPF... 133 The ControlTemplate Template... 133 The DataTemplate Template... 135 Exploring Triggers in WPF... 136 The Property Trigger... 137 Event Triggers... 138 Multi Triggers... 139 Data Triggers... 140 Exploring Commands in WPF... 142 v
WPF 4.0 in Simple Steps Command Sources... 143 Command Targets... 143 Command Binding... 143 Command Usage... 143 Summary... 144 Chapter 6 Working with Typography in WPF 145 ExploringTypography Features in WPF 4.0... 146 Text Rendering by Using the Microsoft ClearType Technology... 146 Support for the OpenType Font Format and International Fonts... 146 Enhanced Text Application Programming Interfaces (APIs)... 147 Exploring Important Classes of Typography... 147 The TextDecoration Class... 147 The Typography Class... 148 The Transform Class... 149 The TextEffect Class... 151 The BitMapEffect Class... 151 Working with Typography... 152 Displaying Special Characters... 152 Adding Decorations to Text... 154 Wrapping Text... 156 Trimming Text... 157 Transforming Text... 159 Animating Text... 160 Adding Shadows to Text... 162 Applying the Blur Effect to Text... 164 Summary... 164 Chapter 7 Working with Documents in WPF 165 Exploring Types of WPF 4.0 Documents... 166 Fixed Documents... 166 Flow Documents... 171 Exploring Serialization and Deserialization of WPF 4.0 Documents... 183 Summary... 184 vi
Table of Contents Chapter 8 Working with Graphics in WPF 185 Exploring 2-D Graphics in WPF 4.0... 186 Working with 2-D Shapes... 186 Using Basic 2-D Shapes... 187 Working with 2-D Geometries... 191 Working with 2-D Brushes... 199 Working with 2-D Drawings... 209 Exploring 3-D Graphics in WPF 4.0... 209 3-D Scenes... 210 Cameras... 210 Lights... 213 Creation of a 3-D Scene... 215 Summary... 216 Chapter 9 Working with Animations and Multimedia in WPF 217 Exploring Animation in WPF 4.0... 218 Exploring Essentials of Animation in WPF 4.0... 218 Exploring Types of Animations... 225 Exploring Multimedia in WPF 4.0... 237 Images... 237 Audio and Video... 242 Summary... 246 Chapter 10 Data Binding in WPF 247 Introducing the Binding Class... 248 Introducing the Components of WPF Data Bindings... 249 Understanding Data Binding Declarations... 250 Declaring Data Binding in the XAML Code... 250 Declaring Data Binding in the Code-Behind File... 252 Working with Data Binding Sources... 253 Binding to CLR Objects... 253 Binding to DependencyObject Objects... 258 Binding to an ADO.NET Object... 260 Binding to an XML Object... 263 Exploring Data Flow Directions... 266 Understanding the OneTime Binding Mode... 266 vii
WPF 4.0 in Simple Steps Understanding the OneWay Binding Mode... 267 Understanding the TwoWay Binding Mode... 267 Understanding the OneWayToSource Binding Mode... 267 Implementing Data Validation... 268 Summary... 272 Chapter 11 Working with Animations and Multimedia in WPF 273 Exploring Deployment Technologies... 274 The Windows Installer Deployment Technology... 274 The ClickOnce Deployment Technology... 275 The XCopy Deployment Technology... 275 Deploying WPF Standalone Applications... 276 Deploying XBAPs... 277 Summary... 279 viii