Suchen und Finden
Table of Contents
5
About the Author
27
About the Technical Reviewer
28
Acknowledgments
29
Introduction
30
About This Book
31
Chapter Overview
31
What You Need to Use This Book
33
Code Samples and URLs
34
Feedback
34
CHAPTER 1 Introducing WPF
35
The Evolution of Windows Graphics
35
DirectX: The New Graphics Engine
36
Hardware Acceleration and WPF
37
WPF: A Higher-Level API
38
Windows Forms Lives On
40
DirectX Also Lives On
40
Silverlight
40
Resolution Independence
41
WPF Units
42
System DPI
43
Windows XP
44
Windows Vista
44
Windows 7
45
Bitmap and Vector Graphics
46
The Architecture of WPF
46
The Class Hierarchy
48
System.Threading.DispatcherObject
49
System.Windows.DependencyObject
49
System.Windows.Media.Visual
49
System.Windows.UIElement
49
System.Windows.FrameworkElement
49
System.Windows.Shapes.Shape
50
System.Windows.Controls.Control
50
System.Windows.Controls.ContentControl
50
System.Windows.Controls.ItemsControl
50
System.Windows.Controls.Panel
50
WPF 4
51
New Features
51
The WPF Toolkit
52
Visual Studio 2010
52
Multitargeting
53
The .NET Client Profile
54
The Visual Studio Designer
54
The Last Word
55
CHAPTER 2 XAML
57
Understanding XAML
58
Graphical User Interfaces Before WPF
58
The Variants of XAML
59
XAML Compilation
60
XAML Basics
61
XAML Namespaces
62
The Code-Behind Class
64
The InitializeComponent() Method
65
Naming Elements
65
Properties and Events in XAML
66
Simple Properties and Type Converters
68
Complex Properties
69
Markup Extensions
71
Attached Properties
72
Nesting Elements
73
Special Characters and Whitespace
76
Events
78
The Full Eight Ball Example
79
Using Types from Other Namespaces
80
Loading and Compiling XAML
82
Code-Only
82
Code and Uncompiled XAML
85
Code and Compiled XAML
87
XAML Only
89
XAML 2009
90
Automatic Event Hookup
90
References
92
Built-in Types
92
Advanced Object Creation
93
The Last Word
94
CHAPTER 3 Layout
95
Understanding Layout in WPF
95
The WPF Layout Philosophy
96
The Layout Process
97
The Layout Containers
97
Simple Layout with the StackPanel
99
Layout Properties
101
Alignment
102
Margin
103
Minimum, Maximum, and Explicit Sizes
105
The Border
108
The WrapPanel and DockPanel
109
The WrapPanel
110
The DockPanel
111
Nesting Layout Containers
113
The Grid
114
Fine-Tuning Rows and Columns
117
Layout Rounding
119
Spanning Rows and Columns
120
Split Windows
121
Shared Size Groups
125
The UniformGrid
127
Coordinate-Based Layout with the Canvas
128
Z-Order
129
The InkCanvas
130
Layout Examples
133
A Column of Settings
133
Dynamic Content
134
A Modular User Interface
136
The Last Word
138
CHAPTER 4 Dependency Properties
139
Understanding Dependency Properties
139
Defining a Dependency Property
140
Registering a Dependency Property
141
Adding a Property Wrapper
143
How WPF Uses Dependency Properties
144
Shared Dependency Properties
145
Attached Dependency Properties
146
Property Validation
148
The Validation Callback
148
The Coercion Callback
149
The Last Word
152
CHAPTER 5 Routed Events
153
Understanding Routed Events
153
Defining, Registering, and Wrapping a Routed Event
154
Sharing Routed Events
155
Raising a Routed Event
155
Handling a Routed Event
155
Event Routing
157
The RoutedEventArgs Class
159
Bubbling Events
160
Handling a Suppressed Event
163
Attached Events
163
Tunneling Events
165
WPF Events
167
Lifetime Events
167
Input Events
170
Keyboard Input
171
Handling a Key Press
172
Focus
174
Getting Key State
175
Mouse Input
177
Mouse Clicks
178
Capturing the Mouse
180
Drag-and-Drop
180
Multitouch Input
183
The Levels of Multitouch Support
184
Raw Touch
184
Manipulation
187
Inertia
190
The Last Word
191
CHAPTER 6 Controls
192
The Control Class
193
Background and Foreground Brushes
193
Setting Colors in Code
193
Setting Colors in XAML
195
Font Family
197
Text Decorations and Typography
197
Font Inheritance
198
Font Substitution
198
Font Embedding
199
Text Formatting Mode
200
Mouse Cursors
201
Content Controls
202
The Content Property
204
Aligning Content
206
The WPF Content Philosophy
207
Labels
208
Buttons
210
The Button
210
The ToggleButton and RepeatButton
211
The CheckBox
211
The RadioButton
212
Tooltips
213
Setting ToolTip Properties
214
Setting ToolTipService Properties
217
The Popup
218
Specialized Containers
221
The ScrollViewer
221
Programmatic Scrolling
223
Custom Scrolling
224
Headered Content Controls
225
The GroupBox
225
The TabItem
226
The Expander
228
Text Controls
230
Multiple Lines of Text
231
Text Selection
232
Spell Checking
233
The PasswordBox
235
List Controls
235
The ListBox
236
The ComboBox
239
Range-Based Controls
240
The Slider
241
The ProgressBar
242
Date Controls
243
The Last Word
246
CHAPTER 7 The Application
247
The Application Life Cycle
247
Creating an Application Object
248
Deriving a Custom Application Class
249
Application Shutdown
250
Application Events
252
Application Tasks
254
Showing a Splash Screen
254
Handling Command-Line Arguments
255
Accessing the Current Application
256
Interacting Between Windows
257
Single-Instance Applications
259
Creating the Single-Instance Application Wrapper
260
Registering the File Type
264
Assembly Resources
266
Adding Resources
266
Retrieving Resources
268
Resource-Aware Classes
269
Pack URIs
269
Resources in Other Assemblies
270
Content Files
271
Localization
271
Building Localizable User Interfaces
272
Preparing an Application for Localization
273
The Translation Process
274
Preparing Markup Elements for Localization
274
Extracting Localizable Content
276
Building a Satellite Assembly
278
The Last Word
280
CHAPTER 8 Element Binding
281
Binding Elements Together
281
The Binding Expression
282
Binding Errors
283
Binding Modes
283
OneWayToSource
285
Default
286
Creating Bindings with Code
286
Multiple Bindings
287
Binding Updates
291
Binding to Objects That Aren’t Elements
292
Source
293
RelativeSource
293
DataContext
295
The Last Word
296
CHAPTER 9 Commands
297
Understanding Commands
297
The WPF Command Model
299
The ICommand Interface
299
The RoutedCommand Class
300
The RoutedUICommand Class
301
The Command Library
301
Executing Commands
303
Command Sources
303
Command Bindings
304
Using Multiple Command Sources
307
Fine-Tuning Command Text
308
Invoking a Command Directly
308
Disabling Commands
309
Controls with Built-in Commands
312
Advanced Commands
314
Custom Commands
314
Using the Same Command in Different Places
316
Using a Command Parameter
318
Tracking and Reversing Commands
318
The Last Word
323
CHAPTER 10 Resources
324
Resource Basics
324
The Resources Collection
325
The Hierarchy of Resources
326
Static and Dynamic Resources
328
Nonshared Resources
330
Accessing Resources in Code
330
Application Resources
331
System Resources
332
Resource Dictionaries
333
Creating a Resource Dictionary
333
Using a Resource Dictionary
334
Sharing Resources Between Assemblies
335
The Last Word
338
CHAPTER 11 Styles and Behaviors
339
Style Basics
339
Creating a Style Object
343
Setting Properties
344
Attaching Event Handlers
346
The Many Layers of Styles
347
Automatically Applying Styles by Type
349
Triggers
350
A Simple Trigger
351
Behaviors
355
Getting Support for Behaviors
355
Understanding the Behavior Model
356
Creating a Behavior
357
Using a Behavior
359
Design-Time Behavior Support in Blend
360
The Last Word
361
CHAPTER 12 Shapes, Brushes, and Transforms
362
Understanding Shapes
362
The Shape Classes
363
Rectangle and Ellipse
366
Sizing and Placing Shapes
367
Scaling Shapes with a Viewbox
370
Line
372
Polyline
373
Polygon
374
Line Caps and Line Joins
377
Dashes
378
Pixel Snapping
380
Brushes
381
The SolidColorBrush
382
The LinearGradientBrush
383
The RadialGradientBrush
385
The ImageBrush
387
A Tiled ImageBrush
389
The VisualBrush
392
The BitmapCacheBrush
393
Transforms
394
Transforming Shapes
396
Transforming Elements
398
Transparency
399
Making an Element Partially Transparent
399
Opacity Masks
401
The Last Word
403
CHAPTER 13 Geometries and Drawings
404
Paths and Geometries
404
Line, Rectangle, and Ellipse Geometries
405
Combining Shapes with GeometryGroup
406
Fusing Geometries with CombinedGeometry
408
Curves and Lines with PathGeometry
412
Straight Lines
413
Arcs
414
Bézier Curves
416
The Geometry Mini-Language
417
Clipping with Geometry
420
Drawings
421
Displaying a Drawing
423
Exporting Clip Art
425
The Last Word
427
CHAPTER 14 Effects and Visuals
428
Visuals
428
Drawing Visuals
429
Wrapping Visuals in an Element
431
Hit Testing
434
Complex Hit Testing
437
Effects
440
BlurEffect
441
DropShadowEffect
442
ShaderEffect
443
The WriteableBitmap Class
445
Generating a Bitmap
445
Writing to a WriteableBitmap
446
More Efficient Pixel Writing
448
The Last Word
451
CHAPTER 15 Animation Basics
452
Understanding WPF Animation
452
Timer-Based Animation
453
Property-Based Animation
454
Basic Animation
455
The Animation Classes
455
Animations in Code
458
From
459
To
461
By
462
Duration
463
Simultaneous Animations
463
Animation Lifetime
463
The Timeline Class
465
AccelerationRatio and DecelerationRatio
467
RepeatBehavior
467
Storyboards
468
The Storyboard
469
Event Triggers
469
Attaching Triggers with a Style
471
Overlapping Animations
472
Synchronized Animations
473
Controlling Playback
474
Monitoring Progress
479
Animation Easing
481
Using an Easing Function
481
Easing In and Easing Out
482
Easing Function Classes
484
Creating a Custom Easing Function
487
Animation Performance
489
Desired Frame Rate
489
Bitmap Caching
492
The Last Word
494
CHAPTER 16 Advanced Animation
495
Animation Types Revisited
495
Animating Transforms
496
Animating Multiple Transforms
499
Animating Brushes
500
VisualBrush
502
Animating Pixel Shaders
503
Key Frame Animation
505
Discrete Key Frame Animations
506
Easing Key Frames
507
Spline Key Frame Animations
508
Path-Based Animation
509
Frame-Based Animation
511
Storyboards in Code
515
The Main Window
516
The Bomb User Control
518
Dropping the Bombs
519
Intercepting a Bomb
522
Counting Bombs and Cleaning Up
524
The Last Word
526
CHAPTER 17 Control Templates
527
Understanding Logical Trees and Visual Trees
528
Understanding Templates
534
The Chrome Classes
537
Dissecting Controls
538
Creating Control Templates
541
A Simple Button
542
Template Bindings
543
Triggers That Change Properties
545
Triggers That Use Animation
548
Organizing Template Resources
549
Refactoring the Button Control Template
550
Applying Templates with Styles
552
Applying Templates Automatically
555
User-Selected Skins
556
Building More Complex Templates
558
Nested Templates
559
Modifying the Scroll Bar
561
The Control Template Examples
566
Visual States
568
The Last Word
569
CHAPTER 18 Custom Elements
571
Understanding Custom Elements in WPF
572
Building a Basic User Control
575
Defining Dependency Properties
576
Defining Routed Events
579
Adding Markup
580
Using the Control
582
Command Support
583
More Robust Commands
585
A Closer Look at User Controls
586
Creating a Lookless Control
587
Refactoring the Color Picker Code
588
Refactoring the Color Picker Markup
588
Streamlining the Control Template
591
Adding Part Names
591
Manipulating Template Parts
592
Documenting Template Parts
594
Theme-Specific Styles and the Default Style
594
Supporting Visual States
596
Starting the FlipPanel Class
597
Choosing Parts and States
600
The Default Control Template
601
The Flip Button
602
Defining the State Animations
603
Defining the State Transitions
604
Wiring Up the Elements
606
Using the FlipPanel
608
Using a Different Control Template
609
Custom Panels
610
The Two-Step Layout Process
611
MeasureOverride()
611
ArrangeOverride()
613
The Canvas Clone
614
A Better Wrapping Panel
615
Custom-Drawn Elements
618
The OnRender() Method
619
Evaluating Custom Drawing
620
A Custom-Drawn Element
621
A Custom Decorator
623
The Last Word
625
CHAPTER 19 Data Binding
626
Binding to a Database with Custom Objects
626
Building a Data Access Component
627
Building a Data Object
630
Displaying the Bound Object
631
Updating the Database
633
Change Notification
634
Binding to a Collection of Objects
636
Displaying and Editing Collection Items
637
Inserting and Removing Collection Items
641
Binding to the ADO.NET Objects
642
Binding to a LINQ Expression
643
Improving Performance in Large Lists
646
Virtualization
646
Item Container Recycling
648
Deferred Scrolling
648
Validation
648
Validation in the Data Object
649
The ExceptionValidationRule
650
The DataErrorValidationRule
651
Custom Validation Rules
653
Reacting to Validation Errors
655
Getting a List of Errors
656
Showing a Different Error Indicator
657
Validating Multiple Values
660
Data Providers
663
The ObjectDataProvider
664
Error Handling
665
Asynchronous Support
665
The XmlDataProvider
667
The Last Word
669
CHAPTER 20 Formatting Bound Data
670
Data Binding Redux
670
Data Conversion
672
The StringFormat Property
672
Introducing Value Converters
674
Formatting Strings with a Value Converter
675
Creating Objects with a Value Converter
677
Applying Conditional Formatting
680
Evaluating Multiple Properties
681
List Controls
683
List Styles
685
The ItemContainerStyle
686
A ListBox with Check Boxes or Radio Buttons
687
Alternating Item Style
690
Style Selectors
692
Data Templates
695
Separating and Reusing Templates
698
More Advanced Templates
699
Varying Templates
702
Template Selectors
703
Templates and Selection
706
Changing Item Layout
711
The ComboBox
713
The Last Word
716
CHAPTER 21 Data Views
717
The View Object
717
Retrieving a View Object
718
Navigating with a View
718
Creating a View Declaratively
721
Filtering, Sorting, and Grouping
723
Filtering Collections
723
Filtering the DataTable
727
Sorting
728
Grouping
729
The Last Word
733
CHAPTER 22 Lists, Grids, and Trees
734
The ListView
735
Creating Columns with the GridView
736
Resizing Columns
737
Cell Templates
737
Creating a Custom View
740
The View Class
742
The View Styles
743
Using the ListView
745
Passing Information to a View
747
The TreeView
749
A Data-Bound TreeView
749
Binding a DataSet to a TreeView
753
Just-in-Time Node Creation
754
The DataGrid
757
Resizing and Rearranging Columns
759
Defining Columns
760
The DataGridCheckBoxColumn
761
DataGridHyperlinkColumn
762
DataGridComboBoxColumn
762
The DataGridTemplateColumn
764
Formatting and Styling Columns
765
Formatting Rows
767
Row Details
769
Freezing Columns
770
Selection
770
Sorting
771
DataGrid Editing
771
The Last Word
774
CHAPTER 23 Windows
775
The Window Class
775
Showing a Window
778
Positioning a Window
779
Saving and Restoring Window Location
780
Window Interaction
782
Window Ownership
784
The Dialog Model
785
Common Dialog Boxes
786
Nonrectangular Windows
787
A Simple Shaped Window
787
A Transparent Window with Shaped Content
790
Moving Shaped Windows
792
Resizing Shaped Windows
793
Putting It All Together: A Custom Control Template for Windows
794
The Aero Glass Effect
798
Programming the Windows 7 Taskbar
803
Using Jump Lists
803
Recent Document Support
803
Custom Jump Lists
805
Creating Jump List Items in Code
807
Launching Application Tasks from the Jump List
808
Changing the Taskbar Icon and Preview
808
Thumbnail Clipping
809
Thumbnail Buttons
810
Progress Notification
812
Overlay Icons
812
The Last Word
814
CHAPTER 24 Pages and Navigation
815
Understanding Page-Based Navigation
815
Page-Based Interfaces
816
A Simple Page-Based Application with NavigationWindow
817
The Page Class
819
Hyperlinks
820
Navigating to Websites
821
Fragment Navigation
822
Hosting Pages in a Frame
823
Hosting Pages in Another Page
824
Hosting Pages in a Web Browser
826
The Page History
827
A Closer Look at URIs in WPF
827
Navigation History
828
Maintaining Custom Properties
829
The Navigation Service
830
Programmatic Navigation
830
Navigation Events
832
Managing the Journal
833
Adding Custom Items to the Journal
835
Page Functions
840
XAML Browser Applications
843
XBAP Requirements
843
Creating an XBAP
844
Deploying an XBAP
845
Updating an XBAP
847
XBAP Security
848
Full-Trust XBAPs
850
Combination XBAP/Stand-Alone Applications
850
Coding for Different Security Levels
851
Isolated Storage
852
Simulating Dialog Boxes with the Popup Control
853
Embedding an XBAP in a Web Page
856
The WebBrowser Control
857
Navigating to a Page
857
Building a DOM Tree
859
Scripting a Web Page with .NET Code
861
The Last Word
864
CHAPTER 25 Menus, Toolbars, and Ribbons
865
Menus
865
The Menu Class
865
Menu Items
867
The ContextMenu Class
869
Menu Separators
869
Toolbars and Status Bars
870
The ToolBar
871
The Overflow Menu
872
The ToolBarTray
873
The StatusBar
874
Ribbons
875
Adding the Ribbon
876
Styling the Ribbon
877
Commands
878
The Application Menu
879
Tabs, Groups, and Buttons
882
Ribbon Sizing
885
The Quick access Toolbar
887
The Last Word
888
CHAPTER 26 Sound and Video
889
Playing WAV Audio
889
The SoundPlayer
890
The SoundPlayerAction
891
System Sounds
892
The MediaPlayer
892
The MediaElement
895
Playing Audio Programmatically
895
Handling Errors
896
Playing Audio with Triggers
896
Playing Multiple Sounds
899
Changing Volume, Balance, Speed, and Position
900
Synchronizing an Animation with Audio
902
Playing Video
904
Video Effects
904
Speech
908
Speech Synthesis
908
Speech Recognition
910
The Last Word
912
CHAPTER 27 3-D Drawing
913
3-D Drawing Basics
913
The Viewport
914
3-D Objects
914
Geometry
916
Geometry Model and Surfaces
919
Light Sources
920
The Camera
923
Deeper into 3-D
927
Shading and Normals
929
More Complex Shapes
933
Model3DGroup Collections
934
Materials Revisited
936
Texture Mapping
938
Mapping the ImageBrush
938
Video and the VisualBrush
941
Interactivity and Animations
942
Transforms
942
Rotations
943
A Fly Over
945
The Trackball
947
Hit Testing
948
Hit Testing in the Viewport
949
The ModelUIElement3D
950
Hit Testing with the ModelUIElement3D
951
The ContainerUIElement3D
953
2-D Elements on 3-D Surfaces
953
The Last Word
956
CHAPTER 28 Documents
958
Understanding Documents
958
Flow Documents
959
The Flow Elements
960
Formatting Content Elements
962
Constructing a Simple Flow Document
964
Block Elements
965
Paragraph and Run
966
List
967
Table
968
Section
970
BlockUIContainer
971
Inline Elements
972
Preserving Whitespace
973
Floater
974
Figure
977
Interacting with Elements Programmatically
978
Text Justification
981
Read-Only Flow Document Containers
983
Zooming
984
Pages and Columns
985
Loading Documents from a File
987
Printing
988
Editing a Flow Document
989
Loading a File
989
Saving a File
991
Formatting Selected Text
992
Getting Individual Words
995
Fixed Documents
996
Annotations
997
The Annotation Classes
998
Enabling the Annotation Service
999
Creating Annotations
1000
Examining Annotations
1004
Reacting to Annotation Changes
1007
Storing Annotations in a Fixed Document
1008
Customizing the Appearance of Sticky Notes
1008
The Last Word
1009
CHAPTER 29 Printing
1011
Basic Printing
1011
Printing an Element
1012
Transforming Printed Output
1014
Printing Elements Without Showing Them
1017
Printing a Document
1018
Manipulating the Pages in a Document Printout
1021
Custom Printing
1023
Printing with the Visual Layer Classes
1023
Custom Printing with Multiple Pages
1026
Print Settings and Management
1032
Maintaining Print Settings
1032
Printing Page Ranges
1033
Managing a Print Queue
1033
Printing Through XPS
1036
Creating an XPS Document for a Print Preview
1037
Writing to an In-Memory XPS Document
1038
Printing Directly to the Printer via XPS
1039
Asynchronous Printing
1039
The Last Word
1040
CHAPTER 30 Interacting with Windows Forms
1041
Assessing Interoperability
1041
Missing Features in WPF
1042
Mixing Windows and Forms
1044
Adding Forms to a WPF Application
1044
Adding WPF Windows to a Windows Forms Application
1044
Showing Modal Windows and Forms
1045
Showing Modeless Windows and Forms
1045
Visual Styles for Windows Forms Controls
1046
Windows Forms Classes That Don’t Need Interoperability
1047
Creating Windows with Mixed Content
1051
WPF and Windows Forms “Airspace”
1051
Hosting Windows Forms Controls in WPF
1052
WPF and Windows Forms User Controls
1055
Hosting WPF Controls in Windows Forms
1056
Access Keys, Mnemonics, and Focus
1058
Property Mapping
1060
The Last Word
1062
CHAPTER 31 Multithreading
1063
Multithreading
1063
The Dispatcher
1064
The DispatcherObject
1064
The BackgroundWorker
1067
A Simple Asynchronous Operation
1068
Creating the BackgroundWorker
1069
Running the BackgroundWorker
1070
Tracking Progress
1072
Supporting Cancellation
1074
The Last Word
1076
CHAPTER 32 The Add-in Model
1077
Choosing Between MAF and MEF
1077
The Add-in Pipeline
1078
How the Pipeline Works
1079
The Add-in Folder Structure
1081
Preparing a Solution That Uses the Add-in Model
1081
An Application That Uses Add-Ins
1084
The Contract
1084
The Add-in View
1085
The Add-In
1085
The Add-in Adapter
1086
The Host View
1087
The Host Adapter
1087
The Host
1088
Adding More Add-Ins
1091
Interacting with the Host
1092
Visual Add-Ins
1096
The Last Word
1099
CHAPTER 33 ClickOnce Deployment
1100
Understanding Application Deployment
1101
The ClickOnce Installation Model
1102
ClickOnce Limitations
1103
A Simple ClickOnce Publication
1104
Setting the Publisher and Production
1104
Starting the Publish Wizard
1106
Publishing for a Network File Share
1108
Publishing for a Web Server
1108
Publishing for a CD or DVD
1109
Online or Offline
1110
The Deployed File Structure
1111
Installing a ClickOnce Application
1112
Updating a ClickOnce Application
1113
Additional ClickOnce Options
1114
Publish Version
1114
Updates
1114
File Associations
1116
Publish Options
1117
The Last Word
1118
Index
1119
Alle Preise verstehen sich inklusive der gesetzlichen MwSt.