WPF Recipes in C# 2008: A Problem-Solution Approach

Book description

WPF offers amazing new opportunities to .NET programmers in terms of the user interfaces they can deliver to their customers. But this significant technological advance comes with a steep learning curve, requiring the programmer to learn new classes, new syntax, and an entirely new approach to UI development.

Although WPF has been generally available for over a year, commercial take-up has been relatively slow, and the publicly available body of knowledge has been weak in terms of real-world examples and best-practice information.

Using WPF Recipes in C# 2008, you'll find a simple and straightforward approach to solving the problems you face every day. Each solution contains a complete, working example that demonstrates how to make the best use of WPF. You can use the example as a template to solve your own problem or as a base on which to build a solution tailored to your specific needs.

Packed with well-structured and documented solutions to a broad range of common WPF problems, this book, which presents the only WPF recipes currently published, will be a valuable addition to any C# programmer's reference library. Examples included provide you with a rich source of information as you begin to learn and will be an invaluable quick-reference guide once you're a proficient WPF programmer.

The emphasis on solving the day-to-day WPF problems that all programmers face frees you from needing to trawl through weighty programming tomes or sift through API documentation, allowing you to focus on the more interesting and innovative aspects of your project.

Table of contents

  1. Copyright
  2. About the Authors
  3. About the Technical Reviewer
  4. Acknowledgments
  5. 1. Building and Debugging WPF Applications
    1. 1.1. Create a Standard WPF Application
      1. 1.1.1. Problem
      2. 1.1.2. Solution
      3. 1.1.3. How It Works
        1. 1.1.3.1. The Code
    2. 1.2. Handle an Unhandled Exception
      1. 1.2.1. Problem
      2. 1.2.2. Solution
      3. 1.2.3. How It Works
        1. 1.2.3.1. The Code
    3. 1.3. Create and Use a Dependency Property
      1. 1.3.1. Problem
      2. 1.3.2. Solution
      3. 1.3.3. How It Works
        1. 1.3.3.1. The Code
    4. 1.4. Create a Read-Only Dependency Property
      1. 1.4.1. Problem
      2. 1.4.2. Solution
      3. 1.4.3. How It Works
        1. 1.4.3.1. The Code
    5. 1.5. Override a Dependency Property's Metadata
      1. 1.5.1. Problem
      2. 1.5.2. Solution
      3. 1.5.3. How It Works
        1. 1.5.3.1. The Code
    6. 1.6. Add a PropertyChangedValueCallback to Any Dependency Property
      1. 1.6.1. Problem
      2. 1.6.2. Solution
      3. 1.6.3. How It Works
        1. 1.6.3.1. The Code
    7. 1.7. Add Validation to a Dependency Property
      1. 1.7.1. Problem
      2. 1.7.2. Solution
      3. 1.7.3. How It Works
        1. 1.7.3.1. The Code
    8. 1.8. Create and Use an Attached Property
      1. 1.8.1. Problem
      2. 1.8.2. Solution
      3. 1.8.3. How It Works
        1. 1.8.3.1. The Code
    9. 1.9. Create a Dependency Property with Property Value Inheritance
      1. 1.9.1. Problem
      2. 1.9.2. Solution
      3. 1.9.3. How It Works
        1. 1.9.3.1. The Code
    10. 1.10. Merge Two Resource Dictionaries
      1. 1.10.1. Problem
      2. 1.10.2. Solution
      3. 1.10.3. How It Works
        1. 1.10.3.1. The Code
    11. 1.11. Define Application-wide Resources
      1. 1.11.1. Problem
      2. 1.11.2. Solution
      3. 1.11.3. How It Works
        1. 1.11.3.1. The Code
    12. 1.12. Reference a ResourceDictionary in a Different Assembly
      1. 1.12.1. Problem
      2. 1.12.2. Solution
      3. 1.12.3. How It Works
        1. 1.12.3.1. The Code
    13. 1.13. Share Properties Throughout an Application
      1. 1.13.1. Problem
      2. 1.13.2. Solution
      3. 1.13.3. How It Works
        1. 1.13.3.1. The Code
    14. 1.14. Create a Single-Instance Application
      1. 1.14.1. Problem
      2. 1.14.2. Solution
      3. 1.14.3. How It Works
        1. 1.14.3.1. The Code
    15. 1.15. Manage Multiple Windows in an Application
      1. 1.15.1. Problem
      2. 1.15.2. Solution
      3. 1.15.3. How It Works
        1. 1.15.3.1. The Code
    16. 1.16. Debug Data Bindings Using an IValueConverter
      1. 1.16.1. Problem
      2. 1.16.2. Solution
      3. 1.16.3. How It Works
        1. 1.16.3.1. The Code
    17. 1.17. Debug Bindings Using Attached Properties
      1. 1.17.1. Problem
      2. 1.17.2. Solution
      3. 1.17.3. How It Works
        1. 1.17.3.1. The Code
  6. 2. Working with Windows, Forms, and Layout Management
    1. 2.1. Automatically Size the Main Application Window to Accommodate Its Content
      1. 2.1.1. Problem
      2. 2.1.2. Solution
      3. 2.1.3. How it Works
        1. 2.1.3.1. The Code
    2. 2.2. Arrange UI Elements in a Horizontal or Vertical Stack
      1. 2.2.1. Problem
      2. 2.2.2. Solution
      3. 2.2.3. How It Works
        1. 2.2.3.1. The Code
    3. 2.3. Arrange UI Elements into Automatically Wrapping Rows or Columns
      1. 2.3.1. Problem
      2. 2.3.2. Solution
      3. 2.3.3. How It Works
        1. 2.3.3.1. The Code
    4. 2.4. Dock UI Elements to the Edges of a Form
      1. 2.4.1. Problem
      2. 2.4.2. Solution
      3. 2.4.3. How It Works
        1. 2.4.3.1. The Code
    5. 2.5. Arrange UI Elements in a Grid
      1. 2.5.1. Problem
      2. 2.5.2. Solution
      3. 2.5.3. How It Works
        1. 2.5.3.1. The Code
    6. 2.6. Position UI Elements Using Exact Coordinates
      1. 2.6.1. Problem
      2. 2.6.2. Solution
      3. 2.6.3. How It Works
        1. 2.6.3.1. The Code
    7. 2.7. Display Content in a Multitabbed User Interface
      1. 2.7.1. Problem
      2. 2.7.2. Solution
      3. 2.7.3. How It Works
        1. 2.7.3.1. The Code
    8. 2.8. Display Content in a Scrollable User Interface
      1. 2.8.1. Problem
      2. 2.8.2. Solution
      3. 2.8.3. How It Works
        1. 2.8.3.1. The Code
    9. 2.9. Display Content in Resizable Split Panel
      1. 2.9.1. Problem
      2. 2.9.2. Solution
      3. 2.9.3. How It Works
        1. 2.9.3.1. The Code
    10. 2.10. Display Content in an Expander
      1. 2.10.1. Problem
      2. 2.10.2. Solution
      3. 2.10.3. How It Works
        1. 2.10.3.1. The Code
    11. 2.11. Place a Group Box Around a Set of UI Elements
      1. 2.11.1. Problem
      2. 2.11.2. Solution
      3. 2.11.3. How It Works
        1. 2.11.3.1. The Code
    12. 2.12. Display a Message Box
      1. 2.12.1. Problem
      2. 2.12.2. Solution
      3. 2.12.3. How It Works
        1. 2.12.3.1. The Code
    13. 2.13. Display a Pop-up Window
      1. 2.13.1. Problem
      2. 2.13.2. Solution
      3. 2.13.3. How It Works
        1. 2.13.3.1. The Code
    14. 2.14. Display a Border
      1. 2.14.1. Problem
      2. 2.14.2. Solution
      3. 2.14.3. How It Works
        1. 2.14.3.1. The Code
    15. 2.15. Display a Menu
      1. 2.15.1. Problem
      2. 2.15.2. Solution
      3. 2.15.3. How It Works
        1. 2.15.3.1. The Code
    16. 2.16. Display a Toolbar
      1. 2.16.1. Problem
      2. 2.16.2. Solution
      3. 2.16.3. How It Works
        1. 2.16.3.1. The Code
    17. 2.17. Display a Status Bar
      1. 2.17.1. Problem
      2. 2.17.2. Solution
      3. 2.17.3. How It Works
        1. 2.17.3.1. The Code
    18. 2.18. Control the Size of UI Elements in a Form
      1. 2.18.1. Problem
      2. 2.18.2. Solution
      3. 2.18.3. How It Works
        1. 2.18.3.1. The Code
    19. 2.19. Define the Tab Order of UI Elements in a Form
      1. 2.19.1. Problem
      2. 2.19.2. Solution
      3. 2.19.3. How It Works
        1. 2.19.3.1. The Code
  7. 3. Using Standard Controls
    1. 3.1. Display Control Content Surrounded by Braces
      1. 3.1.1. Problem
      2. 3.1.2. Solution
      3. 3.1.3. How It Works
        1. 3.1.3.1. The Code
    2. 3.2. Display Simple Text
      1. 3.2.1. Problem
      2. 3.2.2. Solution
      3. 3.2.3. How It Works
        1. 3.2.3.1. The Code
    3. 3.3. Display a Static Image
      1. 3.3.1. Problem
      2. 3.3.2. Solution
      3. 3.3.3. How It Works
        1. 3.3.3.1. The Code
    4. 3.4. Get Simple Text Input from a User
      1. 3.4.1. Problem
      2. 3.4.2. Solution
      3. 3.4.3. How It Works
        1. 3.4.3.1. The Code
    5. 3.5. Get Rich Text Input from a User
      1. 3.5.1. Problem
      2. 3.5.2. Solution
      3. 3.5.3. How It Works
        1. 3.5.3.1. The Code
    6. 3.6. Load or Save the Content of a RichTextBox
      1. 3.6.1. Problem
      2. 3.6.2. Solution
      3. 3.6.3. How It Works
        1. 3.6.3.1. The Code
    7. 3.7. Display a Password Entry Box
      1. 3.7.1. Problem
      2. 3.7.2. Solution
      3. 3.7.3. How It Works
        1. 3.7.3.1. The Code
    8. 3.8. Spell Check a TextBox or RichTextBox Control in Real Time
      1. 3.8.1. Problem
      2. 3.8.2. Solution
      3. 3.8.3. How It Works
        1. 3.8.3.1. The Code
    9. 3.9. Handle a Button Click
      1. 3.9.1. Problem
      2. 3.9.2. Solution
      3. 3.9.3. How It Works
        1. 3.9.3.1. The Code
    10. 3.10. Generate Click Events Repeatedly While a Button Is Clicked
      1. 3.10.1. Problem
      2. 3.10.2. Solution
      3. 3.10.3. How It Works
        1. 3.10.3.1. The Code
    11. 3.11. Set a Default Button
      1. 3.11.1. Problem
      2. 3.11.2. Solution
      3. 3.11.3. How It Works
        1. 3.11.3.1. The Code
    12. 3.12. Provide Quick Keyboard Access to Text Boxes
      1. 3.12.1. Problem
      2. 3.12.2. Solution
      3. 3.12.3. How It Works
        1. 3.12.3.1. The Code
    13. 3.13. Provide Quick Keyboard Access to Buttons
      1. 3.13.1. Problem
      2. 3.13.2. Solution
      3. 3.13.3. How It Works
        1. 3.13.3.1. The Code
    14. 3.14. Get User Input from a Slider
      1. 3.14.1. Problem
      2. 3.14.2. Solution
      3. 3.14.3. How It Works
        1. 3.14.3.1. The Code
    15. 3.15. Display a Context Menu
      1. 3.15.1. Problem
      2. 3.15.2. Solution
      3. 3.15.3. How It Works
        1. 3.15.3.1. The Code
    16. 3.16. Display a Tool Tip on a Control
      1. 3.16.1. Problem
      2. 3.16.2. Solution
      3. 3.16.3. How It Works
        1. 3.16.3.1. The Code
    17. 3.17. Display a Tool Tip on a Disabled Control
      1. 3.17.1. Problem
      2. 3.17.2. Solution
      3. 3.17.3. How It Works
        1. 3.17.3.1. The Code
    18. 3.18. Control the Display Duration and Position of a Tool Tip
      1. 3.18.1. Problem
      2. 3.18.2. Solution
      3. 3.18.3. How It Works
        1. 3.18.3.1. The Code
    19. 3.19. View and Select Items from a Set of Radio Buttons
      1. 3.19.1. Problem
      2. 3.19.2. Solution
      3. 3.19.3. How It Works
        1. 3.19.3.1. The Code
    20. 3.20. View and Select Items from a Set of Check Boxes
      1. 3.20.1. Problem
      2. 3.20.2. Solution
      3. 3.20.3. How It Works
        1. 3.20.3.1. The Code
    21. 3.21. View and Select Items Using a Tree
      1. 3.21.1. Problem
      2. 3.21.2. Solution
      3. 3.21.3. How It Works
        1. 3.21.3.1. The Code
    22. 3.22. View and Select Items Using a List
      1. 3.22.1. Problem
      2. 3.22.2. Solution
      3. 3.22.3. How It Works
        1. 3.22.3.1. The Code
    23. 3.23. Dynamically Add Items to a List
      1. 3.23.1. Problem
      2. 3.23.2. Solution
      3. 3.23.3. How It Works
        1. 3.23.3.1. The Code
    24. 3.24. View and Select Items Using a Combo Box
      1. 3.24.1. Problem
      2. 3.24.2. Solution
      3. 3.24.3. How It Works
        1. 3.24.3.1. The Code
    25. 3.25. Display a Control Rotated
      1. 3.25.1. Problem
      2. 3.25.2. Solution
      3. 3.25.3. How It Works
        1. 3.25.3.1. The Code
  8. 4. Creating User and Custom Controls
    1. 4.1. Create a User Control
      1. 4.1.1. Problem
      2. 4.1.2. Solution
      3. 4.1.3. How It Works
        1. 4.1.3.1. The Code
    2. 4.2. Set the Content Property of a User Control
      1. 4.2.1. Problem
      2. 4.2.2. Solution
      3. 4.2.3. How It Works
        1. 4.2.3.1. The Code
    3. 4.3. Add Properties to a User Control
      1. 4.3.1. Problem
      2. 4.3.2. Solution
      3. 4.3.3. How It Works
        1. 4.3.3.1. The Code
    4. 4.4. Add Events to a User Control
      1. 4.4.1. Problem
      2. 4.4.2. Solution
      3. 4.4.3. How It Works
        1. 4.4.3.1. The Code
    5. 4.5. Support Application Commands in a User Control
      1. 4.5.1. Problem
      2. 4.5.2. Solution
      3. 4.5.3. How It Works
        1. 4.5.3.1. The Code
    6. 4.6. Add Custom Commands to a User Control
      1. 4.6.1. Problem
      2. 4.6.2. Solution
      3. 4.6.3. How It Works
        1. 4.6.3.1. The Code
    7. 4.7. Set Design Mode Behavior in a User Control
      1. 4.7.1. Problem
      2. 4.7.2. Solution
      3. 4.7.3. How It Works
        1. 4.7.3.1. The Code
    8. 4.8. Create a Lookless Custom Control
      1. 4.8.1. Problem
      2. 4.8.2. Solution
      3. 4.8.3. How It Works
        1. 4.8.3.1. The Code
    9. 4.9. Specify the Parts Required by a Custom Control
      1. 4.9.1. Problem
      2. 4.9.2. Solution
      3. 4.9.3. How It Works
        1. 4.9.3.1. The Code
    10. 4.10. Support UI Automation in a Custom Control
      1. 4.10.1. Problem
      2. 4.10.2. Solution
      3. 4.10.3. How It Works
        1. 4.10.3.1. The Code
    11. 4.11. Create a Custom-Drawn Element
      1. 4.11.1. Problem
      2. 4.11.2. Solution
      3. 4.11.3. How It Works
        1. 4.11.3.1. The Code
    12. 4.12. Create a Numeric TextBox Control
      1. 4.12.1. Problem
      2. 4.12.2. Solution
      3. 4.12.3. How It Works
        1. 4.12.3.1. The Code
    13. 4.13. Create a Scrollable Canvas Control
      1. 4.13.1. Problem
      2. 4.13.2. Solution
      3. 4.13.3. How It Works
        1. 4.13.3.1. The Code
    14. 4.14. Create a Zoomable Canvas Control
      1. 4.14.1. Problem
      2. 4.14.2. Solution
      3. 4.14.3. How It Works
        1. 4.14.3.1. The Code
    15. 4.15. Create a Drag Canvas Control
      1. 4.15.1. Problem
      2. 4.15.2. Solution
      3. 4.15.3. How It Works
        1. 4.15.3.1. The Code
  9. 5. Data Binding
    1. 5.1. Bind to a Property of a UI Element
      1. 5.1.1. Problem
      2. 5.1.2. Solution
      3. 5.1.3. How It Works
        1. 5.1.3.1. The Code
    2. 5.2. Create a Two-Way Binding
      1. 5.2.1. Problem
      2. 5.2.2. Solution
      3. 5.2.3. How It Works
        1. 5.2.3.1. The Code
    3. 5.3. Bind a Property of an Element to Itself
      1. 5.3.1. Problem
      2. 5.3.2. Solution
      3. 5.3.3. How It Works
        1. 5.3.3.1. The Code
    4. 5.4. Bind to CLR Objects
      1. 5.4.1. Problem
      2. 5.4.2. Solution
      3. 5.4.3. How It Works
        1. 5.4.3.1. The Code
    5. 5.5. Bind to an Existing Object Instance
      1. 5.5.1. Problem
      2. 5.5.2. Solution
      3. 5.5.3. How It Works
        1. 5.5.3.1. The Code
    6. 5.6. Bind to XML Data
      1. 5.6.1. Problem
      2. 5.6.2. Solution
      3. 5.6.3. How It Works
        1. 5.6.3.1. The Code
    7. 5.7. Bind to a Method
      1. 5.7.1. Problem
      2. 5.7.2. Solution
      3. 5.7.3. How It Works
        1. 5.7.3.1. The Code
    8. 5.8. Bind to a Command
      1. 5.8.1. Problem
      2. 5.8.2. Solution
      3. 5.8.3. How It Works
        1. 5.8.3.1. The Code
    9. 5.9. Bind to the Values of an Enumeration
      1. 5.9.1. Problem
      2. 5.9.2. Solution
      3. 5.9.3. How It Works
        1. 5.9.3.1. The Code
    10. 5.10. Specify a Default Value for a Binding
      1. 5.10.1. Problem
      2. 5.10.2. Solution
      3. 5.10.3. How It Works
        1. 5.10.3.1. The Code
    11. 5.11. Use Data Templates to Display Bound Data
      1. 5.11.1. Problem
      2. 5.11.2. Solution
      3. 5.11.3. How It Works
        1. 5.11.3.1. The Code
    12. 5.12. Use Value Converters to Convert Bound Data
      1. 5.12.1. Problem
      2. 5.12.2. Solution
      3. 5.12.3. How It Works
        1. 5.12.3.1. The Code
    13. 5.13. Use Data Triggers to Change the Appearance of Bound Data
      1. 5.13.1. Problem
      2. 5.13.2. Solution
      3. 5.13.3. How It Works
        1. 5.13.3.1. The Code
    14. 5.14. Select a DataTemplate Based on Properties of the Data Object
      1. 5.14.1. Problem
      2. 5.14.2. Solution
      3. 5.14.3. How It Works
        1. 5.14.3.1. The Code
    15. 5.15. Specify Validation Rules for a Binding
      1. 5.15.1. Problem
      2. 5.15.2. Solution
      3. 5.15.3. How It Works
        1. 5.15.3.1. The Code
    16. 5.16. Bind to IDataErrorInfo
      1. 5.16.1. Problem
      2. 5.16.2. Solution
      3. 5.16.3. How It Works
        1. 5.16.3.1. The Code
    17. 5.17. Bind to a Collection with the Master-Detail Pattern
      1. 5.17.1. Problem
      2. 5.17.2. Solution
      3. 5.17.3. How It Works
        1. 5.17.3.1. The Code
    18. 5.18. Sort Data in a Collection
      1. 5.18.1. Problem
      2. 5.18.2. Solution
      3. 5.18.3. How It Works
        1. 5.18.3.1. The Code
    19. 5.19. Apply Custom Sorting Logic to a Collection
      1. 5.19.1. Problem
      2. 5.19.2. Solution
      3. 5.19.3. How It Works
        1. 5.19.3.1. The Code
    20. 5.20. Filter Data in a Collection
      1. 5.20.1. Problem
      2. 5.20.2. Solution
      3. 5.20.3. How It Works
        1. 5.20.3.1. The Code
    21. 5.21. Group Data in a Collection
      1. 5.21.1. Problem
      2. 5.21.2. Solution
      3. 5.21.3. How It Works
        1. 5.21.3.1. The Code
    22. 5.22. Apply Custom Grouping to a Collection
      1. 5.22.1. Problem
      2. 5.22.2. Solution
      3. 5.22.3. How It Works
        1. 5.22.3.1. The Code
    23. 5.23. Bind to Application Settings
      1. 5.23.1. Problem
      2. 5.23.2. Solution
      3. 5.23.3. How It Works
        1. 5.23.3.1. The Code
    24. 5.24. Bind to Application Resource Strings
      1. 5.24.1. Problem
      2. 5.24.2. Solution
      3. 5.24.3. How It Works
        1. 5.24.3.1. The Code
  10. 6. Working with Styles, Templates, Skins, and Themes
    1. 6.1. Create a Named Style
      1. 6.1.1. Problem
      2. 6.1.2. Solution
      3. 6.1.3. How It Works
      4. 6.1.4. The Code
    2. 6.2. Create a Typed Style
      1. 6.2.1. Problem
      2. 6.2.2. Solution
      3. 6.2.3. How It Works
      4. 6.2.4. The Code
    3. 6.3. Override Style Properties
      1. 6.3.1. Problem
      2. 6.3.2. Solution
      3. 6.3.3. How It Works
      4. 6.3.4. The Code
    4. 6.4. Inherit from a Common Base Style
      1. 6.4.1. Problem
      2. 6.4.2. Solution
      3. 6.4.3. How It Works
      4. 6.4.4. The Code
    5. 6.5. Change a Control's Appearance on Mouse Over
      1. 6.5.1. Problem
      2. 6.5.2. Solution
      3. 6.5.3. How It Works
      4. 6.5.4. The Code
    6. 6.6. Apply Multiple Triggers to the Same Element
      1. 6.6.1. Problem
      2. 6.6.2. Solution
      3. 6.6.3. How It Works
      4. 6.6.4. The Code
    7. 6.7. Evaluate Multiple Properties for the Same Trigger
      1. 6.7.1. Problem
      2. 6.7.2. Solution
      3. 6.7.3. How It Works
        1. 6.7.3.1. The Code
    8. 6.8. Programmatically Extract an Element's Style
      1. 6.8.1. Problem
      2. 6.8.2. Solution
      3. 6.8.3. How It Works
      4. 6.8.4. The Code
    9. 6.9. Set a Style Programmatically
      1. 6.9.1. Problem
      2. 6.9.2. Solution
      3. 6.9.3. How It Works
        1. 6.9.3.1. The Code
    10. 6.10. Ignore an Implicit Style
      1. 6.10.1. Problem
      2. 6.10.2. Solution
      3. 6.10.3. How It Works
        1. 6.10.3.1. The Code
    11. 6.11. Change the Appearance of Alternate Items in a List
      1. 6.11.1. Problem
      2. 6.11.2. Solution
      3. 6.11.3. How It Works
        1. 6.11.3.1. The Code
    12. 6.12. Change the Appearance of a List Item When It's Selected
      1. 6.12.1. Problem
      2. 6.12.2. Solution
      3. 6.12.3. How It Works
        1. 6.12.3.1. The Code
    13. 6.13. Create a Control Template
      1. 6.13.1. Problem
      2. 6.13.2. Solution
      3. 6.13.3. How It Works
      4. 6.13.4. The Code
    14. 6.14. Put a Control Template into a Style
      1. 6.14.1. Problem
      2. 6.14.2. Solution
      3. 6.14.3. How It Works
        1. 6.14.3.1. The Code
    15. 6.15. Create a Control Template That Can Be Customized by Properties
      1. 6.15.1. Problem
      2. 6.15.2. Solution
      3. 6.15.3. How It Works
        1. 6.15.3.1. The Code
    16. 6.16. Specify Named Parts of a Control Template
      1. 6.16.1. Problem
      2. 6.16.2. Solution
      3. 6.16.3. How It Works
        1. 6.16.3.1. The Code
    17. 6.17. Find ControlTemplate-Generated Elements
      1. 6.17.1. Problem
      2. 6.17.2. Solution
      3. 6.17.3. How It Works
        1. 6.17.3.1. The Code
    18. 6.18. Create a Custom ToolTip Style
      1. 6.18.1. Problem
      2. 6.18.2. Solution
      3. 6.18.3. How It Works
        1. 6.18.3.1. The Code
    19. 6.19. Dynamically Change the Skin of an Application
      1. 6.19.1. Problem
      2. 6.19.2. Solution
      3. 6.19.3. How It Works
        1. 6.19.3.1. The Code
    20. 6.20. Create Styles That Adapt to the Current OS Theme
      1. 6.20.1. Problem
      2. 6.20.2. Solution
      3. 6.20.3. How It Works
        1. 6.20.3.1. The Code
  11. 7. Working with Text, Documents, and Printing
    1. 7.1. Programmatically Insert Text into a RichTextBox
      1. 7.1.1. Problem
      2. 7.1.2. Solution
      3. 7.1.3. How It Works
        1. 7.1.3.1. The Code
    2. 7.2. Apply Syntax Highlighting in a Text Control
      1. 7.2.1. Problem
      2. 7.2.2. Solution
      3. 7.2.3. How It Works
        1. 7.2.3.1. The Code
    3. 7.3. Print a WPF Visual
      1. 7.3.1. Problem
      2. 7.3.2. The Solution
      3. 7.3.3. How It Works
        1. 7.3.3.1. The Code
    4. 7.4. Print a Collection of WPF Visuals
      1. 7.4.1. Problem
      2. 7.4.2. Solution
      3. 7.4.3. How It Works
        1. 7.4.3.1. The Code
    5. 7.5. Configure Printing Options Using a PrintTicket
      1. 7.5.1. Problem
      2. 7.5.2. Solution
      3. 7.5.3. How It Works
        1. 7.5.3.1. The Code
    6. 7.6. Print a Simple Document
      1. 7.6.1. Problem
      2. 7.6.2. Solution
      3. 7.6.3. How It Works
        1. 7.6.3.1. The Code
    7. 7.7. Asynchronously Print a Multipage FixedDocument
      1. 7.7.1. Problem
      2. 7.7.2. Solution
      3. 7.7.3. How It Works
        1. 7.7.3.1. The Code
    8. 7.8. Programmatically Create and Save a Simple FixedDocument
      1. 7.8.1. Problem
      2. 7.8.2. Solution
      3. 7.8.3. How It Works
        1. 7.8.3.1. The Code
    9. 7.9. Use Figures and Floaters in a FlowDocument
      1. 7.9.1. Problem
      2. 7.9.2. Solution
      3. 7.9.3. How It Works
        1. 7.9.3.1. The Code
    10. 7.10. Programmatically Create and Save a FlowDocument
      1. 7.10.1. Problem
      2. 7.10.2. Solution
      3. 7.10.3. How It Works
        1. 7.10.3.1. The Code
    11. 7.11. Asynchronously Save a FixedDocument to an XPS File
      1. 7.11.1. Problem
      2. 7.11.2. Solution
      3. 7.11.3. How It Works
        1. 7.11.3.1. The Code
    12. 7.12. Display a Document
      1. 7.12.1. Problem
      2. 7.12.2. Solution
      3. 7.12.3. How It Works
        1. 7.12.3.1. The Code
    13. 7.13. Annotate a Document with Sticky Notes
      1. 7.13.1. Problem
      2. 7.13.2. Solution
      3. 7.13.3. How It Works
        1. 7.13.3.1. The Code
    14. 7.14. Use Highlighting in a Document
      1. 7.14.1. Problem
      2. 7.14.2. Solution
      3. 7.14.3. How It Works
        1. 7.14.3.1. The Code
    15. 7.15. Load and Save User-Defined Annotations
      1. 7.15.1. Problem
      2. 7.15.2. Solution
      3. 7.15.3. How It Works
        1. 7.15.3.1. The Code
    16. 7.16. Print a Document's Annotations
      1. 7.16.1. Problem
      2. 7.16.2. Solution
      3. 7.16.3. How It Works
        1. 7.16.3.1. The Code
  12. 8. Multithreading
    1. 8.1. Execute a Method Asynchronously Using the Dispatcher Queue
      1. 8.1.1. Problem
      2. 8.1.2. Solution
      3. 8.1.3. How It Works
        1. 8.1.3.1. The Code
    2. 8.2. Load the Data for a Window Asynchronously After It Has Rendered
      1. 8.2.1. Problem
      2. 8.2.2. Solution
      3. 8.2.3. How It Works
        1. 8.2.3.1. The Code
    3. 8.3. Load the Items in a ListBox Asynchronously
      1. 8.3.1. Problem
      2. 8.3.2. Solution
      3. 8.3.3. How It Works
        1. 8.3.3.1. The Code
    4. 8.4. Check Whether You Are Running on the UI Thread
      1. 8.4.1. Problem
      2. 8.4.2. Solution
      3. 8.4.3. How It Works
        1. 8.4.3.1. The Code
    5. 8.5. Ensure That You Are Running on the UI Thread
      1. 8.5.1. Problem
      2. 8.5.2. Solution
      3. 8.5.3. How It Works
        1. 8.5.3.1. The Code
    6. 8.6. Execute a Method Asynchronously Using a Background Worker Thread
      1. 8.6.1. Problem
      2. 8.6.2. Solution
      3. 8.6.3. How It Works
        1. 8.6.3.1. The Code
    7. 8.7. Track the Progress of a Background Worker Thread
      1. 8.7.1. Problem
      2. 8.7.2. Solution
      3. 8.7.3. How It Works
        1. 8.7.3.1. The Code
    8. 8.8. Support the Cancellation of a Background Worker Thread
      1. 8.8.1. Problem
      2. 8.8.2. Solution
      3. 8.8.3. How It Works
        1. 8.8.3.1. The Code
    9. 8.9. Create a Background Worker Thread in XAML
      1. 8.9.1. Problem
      2. 8.9.2. Solution
      3. 8.9.3. How It Works
        1. 8.9.3.1. The Code
    10. 8.10. Update the UI Asynchronously on a Timer
      1. 8.10.1. Problem
      2. 8.10.2. Solution
      3. 8.10.3. How It Works
        1. 8.10.3.1. The Code
    11. 8.11. Show a Continuous Animation During an Asynchronous Process
      1. 8.11.1. Problem
      2. 8.11.2. Solution
      3. 8.11.3. How It Works
        1. 8.11.3.1. The Code
    12. 8.12. Show a ProgressBar While Processing on a Background Thread
      1. 8.12.1. Problem
      2. 8.12.2. Solution
      3. 8.12.3. How It Works
        1. 8.12.3.1. The Code
    13. 8.13. Show a Cancellable ProgressBar While Processing on a Background Thread
      1. 8.13.1. Problem
      2. 8.13.2. Solution
      3. 8.13.3. How It Works
        1. 8.13.3.1. The Code
    14. 8.14. Show a Continuous Progress Bar While Processing on a Background Thread
      1. 8.14.1. Problem
      2. 8.14.2. Solution
      3. 8.14.3. How It Works
        1. 8.14.3.1. The Code
    15. 8.15. Implement Application.DoEvents in WPF
      1. 8.15.1. Problem
      2. 8.15.2. Solution
      3. 8.15.3. How It Works
        1. 8.15.3.1. The Code
    16. 8.16. Create a Separate Thread for Each Window in a Multiwindow Application
      1. 8.16.1. Problem
      2. 8.16.2. Solution
      3. 8.16.3. How It Works
        1. 8.16.3.1. The Code
  13. 9. Working with 2D Graphics
    1. 9.1. Draw a Line
      1. 9.1.1. Problem
      2. 9.1.2. Solution
      3. 9.1.3. How It Works
        1. 9.1.3.1. The Code
    2. 9.2. Draw a Sequence of Connected Lines
      1. 9.2.1. Problem
      2. 9.2.2. Solution
      3. 9.2.3. How It Works
        1. 9.2.3.1. The Code
    3. 9.3. Format Lines
      1. 9.3.1. Problem
      2. 9.3.2. Solution
      3. 9.3.3. How It Works
        1. 9.3.3.1. The Code
    4. 9.4. Draw a Curved Line
      1. 9.4.1. Problem
      2. 9.4.2. Solution
      3. 9.4.3. How It Works
        1. 9.4.3.1. The Code
    5. 9.5. Draw Simple Shapes
      1. 9.5.1. Problem
      2. 9.5.2. Solution
      3. 9.5.3. How It Works
        1. 9.5.3.1. The Code
    6. 9.6. Draw Complex Shapes
      1. 9.6.1. Problem
      2. 9.6.2. Solution
      3. 9.6.3. How It Works
        1. 9.6.3.1. The Code
    7. 9.7. Create Reusable Shapes
      1. 9.7.1. Problem
      2. 9.7.2. Solution
      3. 9.7.3. How It Works
        1. 9.7.3.1. The Code
    8. 9.8. Display a Tool Tip on a Shape
      1. 9.8.1. Problem
      2. 9.8.2. Solution
      3. 9.8.3. How It Works
        1. 9.8.3.1. The Code
    9. 9.9. Display Graphics Elements in a Tool Tip
      1. 9.9.1. Problem
      2. 9.9.2. Solution
      3. 9.9.3. How It Works
        1. 9.9.3.1. The Code
    10. 9.10. Use System Colors in Your Graphics
      1. 9.10.1. Problem
      2. 9.10.2. solution
      3. 9.10.3. How It Works
        1. 9.10.3.1. The Code
    11. 9.11. Draw or Fill a Shape Using a Solid Color
      1. 9.11.1. Problem
      2. 9.11.2. Solution
      3. 9.11.3. How It Works
        1. 9.11.3.1. The Code
    12. 9.12. Fill a Shape with a Linear or Radial Color Gradient
      1. 9.12.1. Problem
      2. 9.12.2. Solution
      3. 9.12.3. How It Works
        1. 9.12.3.1. The Code
    13. 9.13. Fill a Shape with an Image
      1. 9.13.1. Problem
      2. 9.13.2. Solution
      3. 9.13.3. How It Works
        1. 9.13.3.1. The Code
    14. 9.14. Fill a Shape with a Pattern or Texture
      1. 9.14.1. Problem
      2. 9.14.2. Solution
      3. 9.14.3. How It Works
        1. 9.14.3.1. The Code
    15. 9.15. Fill a Shape with a View of Active UI Elements
      1. 9.15.1. Problem
      2. 9.15.2. Solution
      3. 9.15.3. How It Works
        1. 9.15.3.1. The Code
    16. 9.16. Apply Blur Effects on UI Elements
      1. 9.16.1. Problem
      2. 9.16.2. Solution
      3. 9.16.3. How It Works
        1. 9.16.3.1. The Code
    17. 9.17. Apply a Glow Effect to Your UI Elements
      1. 9.17.1. Problem
      2. 9.17.2. Solution
      3. 9.17.3. How It Works
        1. 9.17.3.1. The Code
    18. 9.18. Apply a Drop Shadow Effect to Your UI Elements
      1. 9.18.1. Problem
      2. 9.18.2. Solution
      3. 9.18.3. How It Works
        1. 9.18.3.1. The Code
    19. 9.19. Scale, Skew, Rotate, or Position Graphics Elements
      1. 9.19.1. Problem
      2. 9.19.2. Solution
      3. 9.19.3. How It Works
        1. 9.19.3.1. The Code
  14. 10. Working with 3D Graphics
    1. 10.1. Use 3D in Your Application
      1. 10.1.1. Problem
      2. 10.1.2. Solution
      3. 10.1.3. How It Works
        1. 10.1.3.1. The Code
    2. 10.2. Use a 3D Camera
      1. 10.2.1. Problem
      2. 10.2.2. Solution
      3. 10.2.3. How It Works
        1. 10.2.3.1. The Code
    3. 10.3. Draw a 3D Model
      1. 10.3.1. Problem
      2. 10.3.2. Solution
      3. 10.3.3. How It Works
        1. 10.3.3.1. The Code
    4. 10.4. Light a Scene
      1. 10.4.1. Problem
      2. 10.4.2. Solution
      3. 10.4.3. How It Works
        1. 10.4.3.1. The Code
    5. 10.5. Specify a Material for a Model
      1. 10.5.1. Problem
      2. 10.5.2. Solution
      3. 10.5.3. How It Works
        1. 10.5.3.1. The Code
    6. 10.6. Apply Textures to a Model
      1. 10.6.1. Problem
      2. 10.6.2. Solution
      3. 10.6.3. How It Works
        1. 10.6.3.1. The Code
    7. 10.7. Interact with 3D Objects
      1. 10.7.1. Problem
      2. 10.7.2. Solution
      3. 10.7.3. How It Works
        1. 10.7.3.1. The Code
    8. 10.8. Use a 2D Control in a 3D Scene
      1. 10.8.1. Problem
      2. 10.8.2. Solution
      3. 10.8.3. How It Works
        1. 10.8.3.1. The Code
  15. 11. Creating Animation
    1. 11.1. Animate the Property of a Control
      1. 11.1.1. Problem
      2. 11.1.2. Solution
      3. 11.1.3. How It Works
        1. 11.1.3.1. The Code
    2. 11.2. Animate a Property of a Control Set with a Data Binding
      1. 11.2.1. Problem
      2. 11.2.2. Solution
      3. 11.2.3. How It Works
        1. 11.2.3.1. The Code
    3. 11.3. Remove Animations
      1. 11.3.1. Problem
      2. 11.3.2. Solution
      3. 11.3.3. How It Works
        1. 11.3.3.1. The Code
    4. 11.4. Overlap Animations
      1. 11.4.1. Problem
      2. 11.4.2. Solution
      3. 11.4.3. How It Works
        1. 11.4.3.1. The Code
    5. 11.5. Animate Several Properties in Parallel
      1. 11.5.1. Problem
      2. 11.5.2. Solution
      3. 11.5.3. How It Works
        1. 11.5.3.1. The Code
    6. 11.6. Create a Keyframe-Based Animation
      1. 11.6.1. Problem
      2. 11.6.2. Solution
      3. 11.6.3. How It Works
        1. 11.6.3.1. The Code
    7. 11.7. Control the Progress of an Animation
      1. 11.7.1. Problem
      2. 11.7.2. Solution
      3. 11.7.3. How It Works
        1. 11.7.3.1. The Code
    8. 11.8. Animate the Shape of a Path
      1. 11.8.1. Problem
      2. 11.8.2. Solution
      3. 11.8.3. How It Works
        1. 11.8.3.1. The Code
    9. 11.9. Loop and Reverse an Animation
      1. 11.9.1. Problem
      2. 11.9.2. Solution
      3. 11.9.3. How It Works
        1. 11.9.3.1. The Code
    10. 11.10. Limit the Frame Rate of a Storyboard
      1. 11.10.1. Problem
      2. 11.10.2. Solution
      3. 11.10.3. How It Works
        1. 11.10.3.1. The Code
    11. 11.11. Limit the Frame Rate for All Animations in an Application
      1. 11.11.1. Problem
      2. 11.11.2. Solution
      3. 11.11.3. How It Works
        1. 11.11.3.1. The Code
    12. 11.12. Animate an Object Along a Path
      1. 11.12.1. Problem
      2. 11.12.2. Solution
      3. 11.12.3. How It Works
        1. 11.12.3.1. The Code
    13. 11.13. Play Back Audio or Video with a MediaTimeline
      1. 11.13.1. Problem
      2. 11.13.2. Solution
      3. 11.13.3. How It Works
        1. 11.13.3.1. The Code
    14. 11.14. Synchronize Timeline Animations with a MediaTimeline
      1. 11.14.1. Problem
      2. 11.14.2. Solution
      3. 11.14.3. How It Works
        1. 11.14.3.1. The Code
    15. 11.15. Receive Notification When an Animation Completes
      1. 11.15.1. Problem
      2. 11.15.2. Solution
      3. 11.15.3. How It Works
        1. 11.15.3.1. The Code
    16. 11.16. Animate the Color of a Brush with Indirect Property Targeting
      1. 11.16.1. Problem
      2. 11.16.2. Solution
      3. 11.16.3. How It Works
        1. 11.16.3.1. The Code
    17. 11.17. Control Animations Through Triggers
      1. 11.17.1. Problem
      2. 11.17.2. Solution
      3. 11.17.3. How It Works
        1. 11.17.3.1. The Code
    18. 11.18. Animate Text
      1. 11.18.1. Problem
      2. 11.18.2. Solution
      3. 11.18.3. How It Works
        1. 11.18.3.1. The Code
  16. 12. Dealing with Multimedia and User Input
    1. 12.1. Play System Sounds
      1. 12.1.1. Problem
      2. 12.1.2. Solution
      3. 12.1.3. How It Works
        1. 12.1.3.1. The Code
    2. 12.2. Use Triggers to Play Audio When a User Interacts with a Control
      1. 12.2.1. Problem
      2. 12.2.2. Solution
      3. 12.2.3. How It Works
        1. 12.2.3.1. The Code
    3. 12.3. Play a Media File
      1. 12.3.1. Problem
      2. 12.3.2. Solution
      3. 12.3.3. How It Works
        1. 12.3.3.1. The Code
    4. 12.4. Respond When the User Clicks a UI Element with the Mouse
      1. 12.4.1. Problem
      2. 12.4.2. Solution
      3. 12.4.3. How It Works
        1. 12.4.3.1. The Code
    5. 12.5. Respond When the User Clicks a UI Element in a Container with the Mouse
      1. 12.5.1. Problem
      2. 12.5.2. Solution
      3. 12.5.3. How It Works
        1. 12.5.3.1. The Code
    6. 12.6. Respond When the User Rotates the Mouse Wheel
      1. 12.6.1. Problem
      2. 12.6.2. Solution
      3. 12.6.3. How It Works
        1. 12.6.3.1. The Code
    7. 12.7. Drag Items from a List and Drop Them on a Canvas
      1. 12.7.1. Problem
      2. 12.7.2. Solution
      3. 12.7.3. How It Works
        1. 12.7.3.1. The Code
    8. 12.8. Handle Keyboard Events
      1. 12.8.1. Problem
      2. 12.8.2. Solution
      3. 12.8.3. How It Works
        1. 12.8.3.1. The Code
    9. 12.9. Query Keyboard State
      1. 12.9.1. Problem
      2. 12.9.2. Solution
      3. 12.9.3. How It Works
        1. 12.9.3.1. The Code
    10. 12.10. Suppress Keyboard and Mouse Events
      1. 12.10.1. Problem
      2. 12.10.2. Solution
      3. 12.10.3. How It Works
        1. 12.10.3.1. The Code
  17. 13. Migrating and Windows Forms Interoperability
    1. 13.1. Use WPF Windows in a Windows Forms Application
      1. 13.1.1. Problem
      2. 13.1.2. Solution
      3. 13.1.3. How It Works
        1. 13.1.3.1. The Code
    2. 13.2. Use WPF Controls in Windows Forms
      1. 13.2.1. Problem
      2. 13.2.2. Solution
      3. 13.2.3. How It Works
        1. 13.2.3.1. The Code
    3. 13.3. Use Windows Forms in a WPF Application
      1. 13.3.1. Problem
      2. 13.3.2. Solution
      3. 13.3.3. How It Works
        1. 13.3.3.1. The Code
    4. 13.4. Use Windows Forms Controls in a WPF Window
      1. 13.4.1. Problem
      2. 13.4.2. Solution
      3. 13.4.3. How It Works
        1. 13.4.3.1. The Code

Product information

  • Title: WPF Recipes in C# 2008: A Problem-Solution Approach
  • Author(s):
  • Release date: September 2008
  • Publisher(s): Apress
  • ISBN: 9781430210849