You are previewing WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4.
O'Reilly logo
WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4

Book Description

Build effective user interfaces with Windows Presentation Foundation

Windows Presentation Foundation (WPF) is included with the Windows operating system and provides a programming model for building applications that provide a clear separation between the UI and business logic. Written by a leading expert on Microsoft graphics programming, this richly illustrated book provides an introduction to WPF development and explains fundamental WPF concepts.

Packed with helpful examples, this reference progresses through a range of topics that gradually increase in their complexity. You'll quickly start building applications while you learn how to use both Expression Blend and Visual Studio to build UIs. In addition, the book addresses the needs of programmer who write the code behind the UI and shows you how operations can be performed using both XAML and C#.

Topics Covered:

Overview of WPF

WPF in Visual Studio

Expression Blend

Common Properties

Content Controls

Layout Controls

User Interaction Controls

Two-Dimensional Drawing Controls

Properties

Pens and Brushes

Events and Code-Behind

Resources

Styles and Property Triggers

Event Triggers and Animation

Templates

Themes and Skins

Printing

Data Binding

Commanding

Transformations and Effects

Documents

Navigation-Based Applications

Three-Dimensional Drawing

Silverlight

Even if you only have a minimal amount of experience, by the end of the book, you will be able to build dynamic and responsive user interfaces with WPF.

Note: CD-ROM/DVD and other supplementary materials are not included as part of eBook file.

Table of Contents

  1. Copyright
  2. About the Author
  3. Credits
  4. Acknowledgments
  5. Introduction
    1. Who This Book Is For
    2. What This Book Covers (and What It Doesn't)
    3. How This Book Is Structured
    4. What You Need to Use This Book
    5. Conventions
    6. Source Code
    7. Errata
    8. p2p.wrox.com
  6. 1. WPF Overview
    1. 1.1. WPF in a Nutshell
      1. 1.1.1. What Is WPF?
      2. 1.1.2. What Is XAML?
      3. 1.1.3. Object Trees
        1. 1.1.3.1. Logical Tree
        2. 1.1.3.2. Visual Tree
      4. 1.1.4. Non-Treelike Structure
      5. 1.1.5. What Is Silverlight?
    2. 1.2. Project Types
    3. 1.3. Goals and Benefits
      1. 1.3.1. Better Use of Graphics Hardware
        1. 1.3.1.1. Better Multimedia Support
        2. 1.3.1.2. Transformations
        3. 1.3.1.3. 3D Graphics
        4. 1.3.1.4. Retained-Mode Drawing
        5. 1.3.1.5. High-Resolution Vector Graphics
      2. 1.3.2. Property Binding to Provide Animation
      3. 1.3.3. Property Inheritance
      4. 1.3.4. Styles
      5. 1.3.5. Templates
      6. 1.3.6. Consistent Control Containment
      7. 1.3.7. Separate User Interface and Code-Behind
      8. 1.3.8. New Controls
      9. 1.3.9. Declarative Programming
    4. 1.4. Disadvantages
    5. 1.5. Summary
  7. 2. WPF in Visual Studio
    1. 2.1. New Projects
    2. 2.2. Window Designer
    3. 2.3. XAML Editor
    4. 2.4. Toolbox
    5. 2.5. Solution Explorer
    6. 2.6. Properties Window
    7. 2.7. Window Tabs
    8. 2.8. Code-Behind
      1. 2.8.1. Default Event Handlers
      2. 2.8.2. Non-Default Event Handlers
      3. 2.8.3. Handmade Event Handlers
      4. 2.8.4. Runtime Attached Event Handlers
      5. 2.8.5. Other Visual Basic Event Handlers
    9. 2.9. Summary
  8. 3. Expression Blend
    1. 3.1. New Projects
    2. 3.2. Assets Window
    3. 3.3. Projects Window Tab
    4. 3.4. Window Designer
    5. 3.5. Properties Window
      1. 3.5.1. Brushes
        1. 3.5.1.1. Making Brushes
        2. 3.5.1.2. Gradient Brushes
        3. 3.5.1.3. Transformed Gradient Brushes
        4. 3.5.1.4. Tile Brushes
        5. 3.5.1.5. Image Brush
        6. 3.5.1.6. Drawing Brush
        7. 3.5.1.7. Visual Brush
      2. 3.5.2. Pens
      3. 3.5.3. Property Resources
      4. 3.5.4. Styles
    6. 3.6. Resources Window
    7. 3.7. Objects and Timeline
      1. 3.7.1. Storyboards
    8. 3.8. Triggers
    9. 3.9. Control Toolbox
    10. 3.10. Code-Behind
    11. 3.11. Summary
  9. 4. Common Properties
    1. 4.1. Size and Position
      1. 4.1.1. Alignment
      2. 4.1.2. Other Size and Position Properties
    2. 4.2. Font
    3. 4.3. Color
    4. 4.4. Image Shape
      1. 4.4.1. Gradient Opacity Masks
      2. 4.4.2. Image Opacity Masks
    5. 4.5. Miscellaneous
    6. 4.6. Summary
  10. 5. Content Controls
    1. 5.1. Control Overview
    2. 5.2. Graphical Controls
      1. 5.2.1. Image
      2. 5.2.2. MediaElement
    3. 5.3. Textual Controls
      1. 5.3.1. DocumentViewer
      2. 5.3.2. FlowDocument
        1. 5.3.2.1. FlowDocumentPageViewer
        2. 5.3.2.2. FlowDocumentReader
        3. 5.3.2.3. FlowDocumentScrollViewer
      3. 5.3.3. Label
      4. 5.3.4. Pop-Up
      5. 5.3.5. TextBlock
      6. 5.3.6. ToolTip
    4. 5.4. Spatial Controls
      1. 5.4.1. Border
      2. 5.4.2. BulletDecorator
      3. 5.4.3. GroupBox
      4. 5.4.4. ListView
      5. 5.4.5. ProgressBar
      6. 5.4.6. Separator
      7. 5.4.7. TreeView
    5. 5.5. Summary
  11. 6. Layout Controls
    1. 6.1. Control Overview
    2. 6.2. Canvas
    3. 6.3. DockPanel
    4. 6.4. Expander
    5. 6.5. Grid
    6. 6.6. ScrollViewer
    7. 6.7. StackPanel
    8. 6.8. StatusBar
    9. 6.9. TabControl
    10. 6.10. ToolBar and ToolBarTray
    11. 6.11. UniformGrid
    12. 6.12. Viewbox
    13. 6.13. WindowsFormsHost
    14. 6.14. WrapPanel
    15. 6.15. Summary
  12. 7. User Interaction Controls
    1. 7.1. Control Overview
    2. 7.2. Button
    3. 7.3. CheckBox
    4. 7.4. ComboBox
    5. 7.5. ContextMenu
    6. 7.6. Frame
    7. 7.7. GridSplitter
    8. 7.8. ListBox
    9. 7.9. Menu
    10. 7.10. PasswordBox
    11. 7.11. RadioButton
    12. 7.12. RepeatButton
    13. 7.13. RichTextBox
      1. 7.13.1. Editing Commands
      2. 7.13.2. Spell Checking
      3. 7.13.3. Undo and Redo
      4. 7.13.4. Other Features
    14. 7.14. ScrollBar
    15. 7.15. Slider
    16. 7.16. TextBox
    17. 7.17. Summary
  13. 8. Two-Dimensional Drawing Controls
    1. 8.1. Control Overview
    2. 8.2. Stroke Properties
    3. 8.3. Ellipse
    4. 8.4. Line
    5. 8.5. Path
      1. 8.5.1. Path Mini-Language
      2. 8.5.2. A Path Holding Objects
    6. 8.6. Polygon
    7. 8.7. Polyline
    8. 8.8. Rectangle
    9. 8.9. Summary
  14. 9. Properties
    1. 9.1. Property Basics
    2. 9.2. Type Converters
    3. 9.3. Property Element Syntax
    4. 9.4. Property Inheritance
    5. 9.5. Attached Properties
    6. 9.6. Summary
  15. 10. Pens and Brushes
    1. 10.1. Pens
      1. 10.1.1. Stroke
      2. 10.1.2. StrokeThickness
      3. 10.1.3. StrokeDashArray
      4. 10.1.4. StrokeDashCap
      5. 10.1.5. StrokeDashOffset
      6. 10.1.6. StrokeEndLineCap and StrokeStartLineCap
      7. 10.1.7. StrokeLineJoin
      8. 10.1.8. StrokeMiterLimit
    2. 10.2. Brushes
      1. 10.2.1. FillRule
      2. 10.2.2. SpreadMethod
      3. 10.2.3. SolidColorBrush
      4. 10.2.4. LinearGradientBrush
      5. 10.2.5. RadialGradientBrush
      6. 10.2.6. TileBrush
        1. 10.2.6.1. ImageBrush
        2. 10.2.6.2. DrawingBrush
        3. 10.2.6.3. VisualBrush
    3. 10.3. Summary
  16. 11. Events and Code-Behind
    1. 11.1. Code-behind Files
    2. 11.2. Example Code
    3. 11.3. Event Name Attributes
      1. 11.3.1. Creating Event Handlers in Expression Blend
      2. 11.3.2. Creating Event Handlers in Visual Studio
        1. 11.3.2.1. Double-Clicking a Control
        2. 11.3.2.2. Using the Properties Window
        3. 11.3.2.3. Using XAML IntelliSense
      3. 11.3.3. Relaxed Delegates
    4. 11.4. Event Handlers at Run Time
    5. 11.5. The Handles Clause
    6. 11.6. Summary
  17. 12. Resources
    1. 12.1. Defining Resources
    2. 12.2. Resource Types
      1. 12.2.1. Normal Property Values
      2. 12.2.2. Controls
      3. 12.2.3. Simple Data Types
    3. 12.3. Resource Hierarchies
    4. 12.4. Merged Resource Dictionaries
    5. 12.5. Dynamic Resources
    6. 12.6. Summary
  18. 13. Styles and Property Triggers
    1. 13.1. Simplifying Properties
    2. 13.2. Keys and Target Types
      1. 13.2.1. Non-Specific Target Types
      2. 13.2.2. Multiple Target Types
      3. 13.2.3. Unnamed Styles
    3. 13.3. Property Value Precedence
    4. 13.4. Style Inheritance
    5. 13.5. Triggers
      1. 13.5.1. Text Triggers
      2. 13.5.2. IsMouseOver Triggers
      3. 13.5.3. Setting Transform and BitmapEffect
      4. 13.5.4. Setting Opacity
      5. 13.5.5. IsActive and IsFocused Triggers
    6. 13.6. Summary
  19. 14. Event Triggers and Animation
    1. 14.1. Event Triggers
      1. 14.1.1. Event Trigger Locations
      2. 14.1.2. Storyboards in Property Elements
      3. 14.1.3. Storyboards in Styles
    2. 14.2. Property Trigger Animations
    3. 14.3. Storyboards
      1. 14.3.1. Storyboard and Animation Properties
      2. 14.3.2. Animation Types
        1. 14.3.2.1. Simple Linear Animations
        2. 14.3.2.2. Linear Key Frames
        3. 14.3.2.3. Spline Key Frames
        4. 14.3.2.4. Discrete Key Frames
        5. 14.3.2.5. Path Animations
        6. 14.3.2.6. Mix and Match Key Frames
        7. 14.3.2.7. Special Cases
    4. 14.4. Controlling Storyboards
    5. 14.5. Media and Timelines
    6. 14.6. Animation without Storyboards
    7. 14.7. Easy Animations
    8. 14.8. Summary
  20. 15. Templates
    1. 15.1. Template Overview
    2. 15.2. ContentPresenter
    3. 15.3. Template Binding
    4. 15.4. Changing Control Appearance
    5. 15.5. Template Events
    6. 15.6. Glass Button
      1. 15.6.1. Glass Button Template Overview
      2. 15.6.2. Glass Button Styles
      3. 15.6.3. Glass Button Triggers
    7. 15.7. Ellipse Button
      1. 15.7.1. Ellipse Button Controls
      2. 15.7.2. Ellipse Button Triggers
    8. 15.8. Researching Control Templates
    9. 15.9. Summary
  21. 16. Themes and Skins
    1. 16.1. Themes
      1. 16.1.1. Using the System Theme
      2. 16.1.2. Using a Specific Theme
    2. 16.2. Skins
      1. 16.2.1. Skin Purposes
      2. 16.2.2. Resource Skins
      3. 16.2.3. Animated Skins
      4. 16.2.4. Dynamically Loaded Skins
    3. 16.3. Summary
  22. 17. Printing
    1. 17.1. Printing Visual Objects
      1. 17.1.1. Simple Printing with PrintVisual
      2. 17.1.2. Advanced Printing with PrintVisual
    2. 17.2. Printing Code-Generated Output
    3. 17.3. Printing Documents
      1. 17.3.1. Printing FlowDocuments
      2. 17.3.2. Printing FixedDocuments
    4. 17.4. Summary
  23. 18. Data Binding
    1. 18.1. Binding Basics
      1. 18.1.1. Binding Target and Target Property
      2. 18.1.2. Binding Source
        1. 18.1.2.1. ElementName
        2. 18.1.2.2. Source
        3. 18.1.2.3. RelativeSource
        4. 18.1.2.4. DataContext
      3. 18.1.3. Binding Path
    2. 18.2. Binding Collections
      1. 18.2.1. ListBox and ComboBox Templates
      2. 18.2.2. TreeView Templates
    3. 18.3. Binding Master-Detail Data
    4. 18.4. Binding XAML
    5. 18.5. Binding XML
    6. 18.6. Binding Database Objects
      1. 18.6.1. Loading Data
      2. 18.6.2. Saving Changes
      3. 18.6.3. Binding the Student Name ListBox
      4. 18.6.4. Displaying Student Details
      5. 18.6.5. Binding the Scores ListBox
    7. 18.7. Summary
  24. 19. Commanding
    1. 19.1. Commanding Concepts
    2. 19.2. Predefined Commands with Actions
    3. 19.3. Predefined Commands without Actions
    4. 19.4. Custom Commands
    5. 19.5. Summary
  25. 20. Transformations and Effects
    1. 20.1. Transformations
    2. 20.2. Combining Transformations
    3. 20.3. Layout and Render Transforms
    4. 20.4. Effects
    5. 20.5. Summary
  26. 21. Documents
    1. 21.1. Fixed Documents
      1. 21.1.1. Building XPS Documents
      2. 21.1.2. Displaying XPS Documents
      3. 21.1.3. Building Fixed Documents in XAML
      4. 21.1.4. Saving XPS Files
    2. 21.2. Flow Documents
      1. 21.2.1. BlockUIContainer
      2. 21.2.2. List
      3. 21.2.3. Paragraph
      4. 21.2.4. Section
      5. 21.2.5. Table
    3. 21.3. Summary
  27. 22. Navigation-Based Applications
    1. 22.1. Page
    2. 22.2. Hyperlink Navigation
    3. 22.3. NavigationService
    4. 22.4. Frame
    5. 22.5. Summary
  28. 23. Three-Dimensional Drawing
    1. 23.1. Basic Structure
      1. 23.1.1. Positions
      2. 23.1.2. TriangleIndices
      3. 23.1.3. Outward Orientation
      4. 23.1.4. Normals
      5. 23.1.5. TextureCoordinates
    2. 23.2. Cameras
    3. 23.3. Lighting
    4. 23.4. Materials
    5. 23.5. Building Complex Scenes
      1. 23.5.1. Geometric Shapes
      2. 23.5.2. Charts and Graphs
      3. 23.5.3. Generated Textures
      4. 23.5.4. Surfaces
    6. 23.6. Summary
  29. 24. Silverlight
    1. 24.1. What Is Silverlight?
    2. 24.2. A Color Selection Example
    3. 24.3. A Bouncing Ball Example
    4. 24.4. For More Information
    5. 24.5. Summary
  30. A. Common Properties
    1. A.1. General Properties
    2. A.2. Font Properties
    3. A.3. Drawing Properties
    4. A.4. Bitmap Effect Properties
    5. A.5. Grid Attached Properties
    6. A.6. DockPanel Attached Properties
    7. A.7. Canvas Attached Properties
  31. B. Content Controls
    1. B.1. Border
    2. B.2. BulletDecorator
    3. B.3. DocumentViewer
    4. B.4. FlowDocument
      1. B.4.1. Content Objects
    5. B.5. FlowDocumentPageViewer
    6. B.6. FlowDocumentReader
      1. B.6.1.
        1. B.6.1.1. Viewing Mode Values
    7. B.7. FlowDocumentScrollViewer
    8. B.8. GroupBox
    9. B.9. Image
    10. B.10. Label
    11. B.11. ListView
    12. B.12. MediaElement
    13. B.13. Popup
    14. B.14. ProgressBar
    15. B.15. Separator
    16. B.16. TextBlock
    17. B.17. ToolTip
    18. B.18. TreeView
  32. C. Layout Controls
    1. C.1. Canvas
    2. C.2. DockPanel
    3. C.3. Expander
    4. C.4. Grid
    5. C.5. ScrollViewer
    6. C.6. StackPanel
    7. C.7. StatusBar
    8. C.8. TabControl
    9. C.9. ToolBar and ToolBarTray
    10. C.10. UniformGrid
    11. C.11. Viewbox
    12. C.12. WindowsFormsHost
    13. C.13. WrapPanel
  33. D. User Interaction Controls
    1. D.1. Button
    2. D.2. CheckBox
    3. D.3. ComboBox
    4. D.4. ContextMenu
    5. D.5. Frame
    6. D.6. GridSplitter
    7. D.7. ListBox
    8. D.8. Menu
    9. D.9. PasswordBox
    10. D.10. RadioButton
    11. D.11. RepeatButton
    12. D.12. RichTextBox
    13. D.13. ScrollBar
    14. D.14. Slider
    15. D.15. TextBox
  34. E. MediaElement Control
  35. F. Pens
  36. G. Brushes
    1. G.1. Brush Classes
    2. G.2. DrawingBrush
      1. G.2.1. Drawing Types
    3. G.3. ImageBrush
    4. G.4. LinearGradientBrush
    5. G.5. RadialGradientBrush
    6. G.6. SolidColorBrush
    7. G.7. VisualBrush
    8. G.8. Viewports and Viewboxes
  37. H. Path Mini-Language
  38. I. XPath
    1. I.1. XML in XAML
    2. I.2. Binding to XML Data
    3. I.3. Selection
    4. I.4. Predicates
    5. I.5. Constraint Functions
      1. I.5.1. Selection Expressions
      2. I.5.2. Display Expressions
        1. I.5.2.1. Order Node Selected
        2. I.5.2.2. Item Node Selected
  39. J. Data Binding
    1. J.1. Binding Components
    2. J.2. Binding to Elements by Name
    3. J.3. Binding to RelativeSource
    4. J.4. Binding to Classes in Code-Behind
    5. J.5. Binding to Classes in XAML Code
    6. J.6. Making Collections of Data
      1. J.6.1. Collections in XAML Code
      2. J.6.2. Collections in Code-Behind
    7. J.7. Using ListBox and ComboBox Templates
    8. J.8. Using TreeView Templates
    9. J.9. Binding to XML Data
  40. K. Commanding Classes
    1. K.1. ApplicationCommands
    2. K.2. ComponentCommands
    3. K.3. Editing Commands
    4. K.4. MediaCommands
    5. K.5. NavigationCommands
    6. K.6. Commands in XAML
    7. K.7. Commands in Code-Behind
  41. L. Bitmap Effects
  42. M. Styles
    1. M.1. Named Styles
    2. M.2. Unnamed Styles
    3. M.3. Inherited Styles
  43. N. Templates
    1. N.1. Label
    2. N.2. CheckBox
    3. N.3. RadioButton
    4. N.4. ProgressBar
    5. N.5. Oriented ProgressBar
    6. N.6. Labeled ProgressBar
    7. N.7. ScrollBar
    8. N.8. Modified ScrollBar
    9. N.9. Button
  44. O. Triggers and Animation
    1. O.1. EventTriggers
    2. O.2. Property Triggers
    3. O.3. Storyboard Properties
    4. O.4. Animation Classes
  45. P. Index of Example Programs
    1. P.1. Chapter 1
    2. P.2. Chapter 2
    3. P.3. Chapter 3
    4. P.4. Chapter 4
    5. P.5. Chapter 5
    6. P.6. Chapter 6
    7. P.7. Chapter 7
    8. P.8. Chapter 8
    9. P.9. Chapter 9
    10. P.10. Chapter 10
    11. P.11. Chapter 11
    12. P.12. Chapter 12
    13. P.13. Chapter 13
    14. P.14. Chapter 14
    15. P.15. Chapter 15
    16. P.16. Chapter 16
    17. P.17. Chapter 17
    18. P.18. Chapter 18
    19. P.19. Chapter 19
    20. P.20. Chapter 20
    21. P.21. Chapter 21
    22. P.22. Chapter 22
    23. P.23. Chapter 23
    24. P.24. Chapter 24
    25. P.25. Appendix A
    26. P.26. Appendix B
    27. P.27. Appendix C
    28. P.28. Appendix D
    29. P.29. Appendix E
    30. P.30. Appendix F
    31. P.31. Appendix G
    32. P.32. Appendix H
    33. P.33. Appendix I
    34. P.34. Appendix J
    35. P.35. Appendix K
    36. P.36. Appendix L
    37. P.37. Appendix M
    38. P.38. Appendix N
    39. P.39. Appendix O
    40. P.40. Appendix P