You are previewing Illustrated WPF.
O'Reilly logo
Illustrated WPF

Book Description

Windows Presentation Foundation is Microsoft's newest API for creating Windows applications. It gives the programmer the ability to produce dazzling, graphics-rich programs easily without having to delve into the messy details of the graphics subsystem.

To use this power, however, the programmer must learn new concepts for laying out pages and displaying graphics. Illustrated WPF presents these concepts clearly and visually—making them easier to understand and retain.

Table of Contents

  1. Copyright
  2. About the Author
  3. Acknowledgments
  4. Introduction
    1. Audience, Source Code, and Contact Information
  5. 1. Introduction to Windows Presentation Foundation
    1. 1.1. What Is Windows Presentation Foundation?
    2. 1.2. The Path to the Screen
      1. 1.2.1. Games and DirectX
      2. 1.2.2. Windows Forms
      3. 1.2.3. Rendering Under WPF
    3. 1.3. Documents and Fonts
    4. 1.4. Graphics and Animation
    5. 1.5. Styles and Control Templates
    6. 1.6. Separating Visual Design from Coding
    7. 1.7. WPF Prefers Vector Graphics
      1. 1.7.1. Bitmap Images
        1. 1.7.1.1. Bitmap Images and Screen Size
      2. 1.7.2. Vector Graphics
    8. 1.8. System DPI Independence and WPF Units
    9. 1.9. XAML Browser Applications (XBAPs)
    10. 1.10. The Other Parts of .NET
    11. 1.11. Silverlight
    12. 1.12. Summary
  6. 2. Overview of WPF Programming
    1. 2.1. What Is an API?
    2. 2.2. A Simple WPF Program
      1. 2.2.1. Creating the Simple Program
        1. 2.2.1.1. Just the Facts
        2. 2.2.1.2. Step-by-Step
    3. 2.3. The Compilation Process
    4. 2.4. The Application and Window Classes
    5. 2.5. The Window Class
      1. 2.5.1. The Components of a Visual Window
      2. 2.5.2. Creating a Window
    6. 2.6. Important Properties of a Window
      1. 2.6.1. WindowStyle
      2. 2.6.2. Content
    7. 2.7. Summary
  7. 3. WPF Architecture and Applications
    1. 3.1. Using Visual Studio to Create a WPF Program
      1. 3.1.1. Step-by-Step
      2. 3.1.2. Source Code Generated by the Template
    2. 3.2. What Is XAML?
      1. 3.2.1.
        1. 3.2.1.1. Logical Trees and Visual Trees
    3. 3.3. The Compilation Process
      1. 3.3.1. How the Files Are Used
    4. 3.4. The WPF Architecture
    5. 3.5. More About the Window Class
      1. 3.5.1. SolidColorBrushes
        1. 3.5.1.1. Creating Colors
      2. 3.5.2. Gradient Brushes
        1. 3.5.2.1. Linear Gradient Brushes
        2. 3.5.2.2. RadialGradientBrushes
    6. 3.6. The Application Class
    7. 3.7. Handling Application Events
      1. 3.7.1. Application Lifetime Events
    8. 3.8. UI Elements Contain Content
    9. 3.9. The Class Inheritance Hierarchy
    10. 3.10. Summary
  8. 4. XAML
    1. 4.1. A Tree of Objects
      1. 4.1.1. Using XamlPad
    2. 4.2. Creating the UI Structure
    3. 4.3. XAML Trees
    4. 4.4. Object Element Syntax
      1. 4.4.1. The Syntax of Elements
    5. 4.5. Attribute Syntax
      1. 4.5.1. Empty Elements
    6. 4.6. More About Object Element Syntax
      1. 4.6.1.
        1. 4.6.1.1. The Default Content Property
    7. 4.7. Type Converters for Attributes
    8. 4.8. Property Element Syntax
    9. 4.9. Attached Property Syntax
      1. 4.9.1. Reviewing the XAML Syntax Forms
      2. 4.9.2. Top-Level Elements
    10. 4.10. Code-Behind and Object Names
    11. 4.11. Namespaces
      1. 4.11.1. The Syntax of Namespaces
      2. 4.11.2. Using Classes from Other Namespaces
        1. 4.11.2.1. Example Using Namespaces
    12. 4.12. Markup Extensions
      1. 4.12.1.
        1. 4.12.1.1. Example Creating a Markup Extension
    13. 4.13. White Space
    14. 4.14. Special Characters
    15. 4.15. Summary
  9. 5. Layout
    1. 5.1. Layout in WPF
    2. 5.2. Chapter Conventions
    3. 5.3. The Layout Process
    4. 5.4. Setting the Requested Size of Elements
    5. 5.5. Alignment
    6. 5.6. Content Alignment
    7. 5.7. Visibility
    8. 5.8. Padding and Margins
    9. 5.9. Panels
    10. 5.10. The StackPanel
    11. 5.11. The WrapPanel
    12. 5.12. The DockPanel
    13. 5.13. The Grid
      1. 5.13.1. Items Spanning Cells
      2. 5.13.2. Sizing Rows and Columns
        1. 5.13.2.1. Absolute Sizing
        2. 5.13.2.2. Automatic Sizing
        3. 5.13.2.3. Proportional Sizing
      3. 5.13.3. Splitter Bars
      4. 5.13.4. Shared Size Groups
    14. 5.14. The Canvas
      1. 5.14.1. Z-Order on a Canvas
    15. 5.15. The UniformGrid
    16. 5.16. Summary
  10. 6. Content and Controls
    1. 6.1. Liberating Content
    2. 6.2. Source Code Conventions
    3. 6.3. The Image Element
      1. 6.3.1. Displaying an Image Using Code
    4. 6.4. The ContentControls
      1. 6.4.1. The Label Control
      2. 6.4.2. The Button Control
      3. 6.4.3. The CheckBox and RadioButton Controls
        1. 6.4.3.1. Grouping RadioButtons
      4. 6.4.4. The Window Class
        1. 6.4.4.1. Window Ownership
        2. 6.4.4.2. Modal Dialog Boxes
        3. 6.4.4.3. The MessageBox Dialog Box
      5. 6.4.5. The ScrollViewer
    5. 6.5. The HeaderedContentControls
      1. 6.5.1. The GroupBox Element
      2. 6.5.2. The Expander Control
    6. 6.6. ItemsControl Elements
      1. 6.6.1. The ListBox Control
        1. 6.6.1.1. Checking the Selection
        2. 6.6.1.2. Notification of Changed Selection
      2. 6.6.2. Multiple Selections
      3. 6.6.3. The ComboBox Control
        1. 6.6.3.1. Selecting and Entering Items
    7. 6.7. Summary
  11. 7. Dependency Properties
    1. 7.1. Properties and a New Paradigm
    2. 7.2. Looking at an Example
    3. 7.3. Determining the Value of a Property
    4. 7.4. The Infrastructure of a Dependency Property
    5. 7.5. Creating a Custom Dependency Property
    6. 7.6. Example: Creating a Dependency Property
    7. 7.7. Attached Properties
    8. 7.8. The Structure of an Attached Property
    9. 7.9. Creating an Attached Property
    10. 7.10. Summary
  12. 8. Data Binding
    1. 8.1. What Is Data Binding?
    2. 8.2. The Binding Object
    3. 8.3. Binding Direction
    4. 8.4. Triggers
    5. 8.5. Data Converters
    6. 8.6. Multiple Bindings on an Element
    7. 8.7. More Fun with Multiple Bindings
    8. 8.8. Deleting Bindings
    9. 8.9. Binding to Nonelements
    10. 8.10. Data Contexts
    11. 8.11. Bindings and ItemsControls
    12. 8.12. Summary
  13. 9. Routing Events and Commands
    1. 9.1. What Is an Event?
    2. 9.2. Event Handlers: Syntax and Semantics
      1. 9.2.1. Attaching a Handler to an Event
    3. 9.3. What Are Routed Events?
      1. 9.3.1. Handling Routed Events
      2. 9.3.2. Bubbling Example
      3. 9.3.3. Checking for Tunneling
    4. 9.4. Commands
    5. 9.5. Built-in Commands and Support
    6. 9.6. The RoutedCommand Class
    7. 9.7. Creating Custom Commands
      1. 9.7.1. Routing Commands
    8. 9.8. Summary
  14. 10. Other Controls and Elements
    1. 10.1. The TextBox Control
    2. 10.2. Menus
      1. 10.2.1. Adorning the MenuItem
      2. 10.2.2. Other Content As the Menu Header
      3. 10.2.3. Attaching Commands to Menu Items
    3. 10.3. Context Menus
    4. 10.4. ToolBars
    5. 10.5. StatusBars
    6. 10.6. ToolTips
    7. 10.7. Controls That Work with Ranges
      1. 10.7.1. The ProgressBar
      2. 10.7.2. The Slider
    8. 10.8. Summary
  15. 11. Resources
    1. 11.1. Two Types of Resources
    2. 11.2. The ResourceDictionary
      1. 11.2.1. StaticResources and DynamicResources
    3. 11.3. Assembly Resources
    4. 11.4. Accessing Assembly Resources from the Code
      1. 11.4.1. Pack URIs
    5. 11.5. Summary
  16. 12. Styles
    1. 12.1. What Are Styles?
    2. 12.2. Named Styles
    3. 12.3. Targeted Styles
    4. 12.4. Comparing Named and Targeted Styles
    5. 12.5. EventSetters
    6. 12.6. The Collections in a Style
    7. 12.7. Property Triggers
    8. 12.8. MultiTriggers
    9. 12.9. Other Types of Triggers
    10. 12.10. Summary
  17. 13. Control Templates
    1. 13.1. Separating Appearance from Behavior
    2. 13.2. Developing a Simple Control Template
    3. 13.3. The ContentPresenter Class
    4. 13.4. Template Binding
    5. 13.5. ControlTemplate Triggers
    6. 13.6. Summary
  18. 14. Page Navigation Programs
    1. 14.1. Types of Navigation
      1. 14.1.1. The Components of a Navigation Program
        1. 14.1.1.1. Frames
        2. 14.1.1.2. Journal Options in Frames
    2. 14.2. Navigating Programmatically
      1. 14.2.1. Passing Data to a Page
      2. 14.2.2. Getting Data Back from a Page
    3. 14.3. XAML Browser Applications
      1. 14.3.1. Creating an XBAP Application
        1. 14.3.1.1. Deploying and Running
    4. 14.4. Summary
  19. 15. More Data Binding
    1. 15.1. Data Templates
    2. 15.2. Views
    3. 15.3. Filtering in a View
    4. 15.4. Sorting in a View
    5. 15.5. Grouping in a View
    6. 15.6. Summary
  20. 16. Trees, Tabs, and Other Controls
    1. 16.1. The TreeView Control
    2. 16.2. The HierarchicalDataTemplate
    3. 16.3. Using Event Handlers with TreeViews
    4. 16.4. Binding Other Controls to a TreeView
    5. 16.5. The TabControl
    6. 16.6. The Calendar Control
    7. 16.7. The DatePicker Control
    8. 16.8. The DataGrid Control
    9. 16.9. Summary
  21. 17. Text and Documents
    1. 17.1. Text in WPF
    2. 17.2. An Overview of Flow Documents
    3. 17.3. The Components of a Flow Document
      1. 17.3.1. The Hosting Controls
    4. 17.4. The Content of a Flow Document
      1. 17.4.1. Tables and Lists
    5. 17.5. Embedded Flow Documents
    6. 17.6. The TextBlock Element
    7. 17.7. Summary
  22. 18. Graphics in WPF
    1. 18.1. Graphics in WPF
    2. 18.2. Transforms
      1. 18.2.1. The RotateTransform
      2. 18.2.2. Using LayoutTransform vs. RenderTransform
      3. 18.2.3. The TranslateTransform
      4. 18.2.4. The SkewTransform
      5. 18.2.5. The ScaleTransform
      6. 18.2.6. BitmapEffects
    3. 18.3. Brushes
      1. 18.3.1.
        1. 18.3.1.1. LinearGradientBrushes
    4. 18.4. Shapes
    5. 18.5. The Geometry Classes
      1. 18.5.1. The Simple Geometry Classes
      2. 18.5.2. The PathGeometry Class
        1. 18.5.2.1. The LineSegment and the PolyLineSegment
        2. 18.5.2.2. The ArcSegment
        3. 18.5.2.3. Combining Geometries
        4. 18.5.2.4. Path Markup Syntax
      3. 18.5.3. Filling Geometries
    6. 18.6. Drawings
      1. 18.6.1. The DrawingImage Class
      2. 18.6.2. The DrawingBrush Class
    7. 18.7. Summary
  23. 19. Animation
    1. 19.1. What Is Animation?
    2. 19.2. Animation Object Basics
    3. 19.3. The AnimationClock Class
    4. 19.4. Storyboards
      1. 19.4.1. Storyboards in Markup
    5. 19.5. Other Variations on Animation
    6. 19.6. Keyframe Animations
      1. 19.6.1. Linear Keyframe Animation
      2. 19.6.2. Spline Interpolation Animations
      3. 19.6.3. Discrete Keyframe Animation
    7. 19.7. Path Animations
    8. 19.8. Summary
  24. 20. Audio and Video
    1. 20.1. Overview of Audio
      1. 20.1.1. SystemSounds
    2. 20.2. SoundPlayer
      1. 20.2.1. SoundPlayerAction
    3. 20.3. MediaPlayer
    4. 20.4. MediaElement
    5. 20.5. Video
    6. 20.6. Summary