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
- Copyright
- About the Authors
- About the Technical Reviewer
- Acknowledgments
-
1. Building and Debugging WPF Applications
- 1.1. Create a Standard WPF Application
- 1.2. Handle an Unhandled Exception
- 1.3. Create and Use a Dependency Property
- 1.4. Create a Read-Only Dependency Property
- 1.5. Override a Dependency Property's Metadata
- 1.6. Add a PropertyChangedValueCallback to Any Dependency Property
- 1.7. Add Validation to a Dependency Property
- 1.8. Create and Use an Attached Property
- 1.9. Create a Dependency Property with Property Value Inheritance
- 1.10. Merge Two Resource Dictionaries
- 1.11. Define Application-wide Resources
- 1.12. Reference a ResourceDictionary in a Different Assembly
- 1.13. Share Properties Throughout an Application
- 1.14. Create a Single-Instance Application
- 1.15. Manage Multiple Windows in an Application
- 1.16. Debug Data Bindings Using an IValueConverter
- 1.17. Debug Bindings Using Attached Properties
-
2. Working with Windows, Forms, and Layout Management
- 2.1. Automatically Size the Main Application Window to Accommodate Its Content
- 2.2. Arrange UI Elements in a Horizontal or Vertical Stack
- 2.3. Arrange UI Elements into Automatically Wrapping Rows or Columns
- 2.4. Dock UI Elements to the Edges of a Form
- 2.5. Arrange UI Elements in a Grid
- 2.6. Position UI Elements Using Exact Coordinates
- 2.7. Display Content in a Multitabbed User Interface
- 2.8. Display Content in a Scrollable User Interface
- 2.9. Display Content in Resizable Split Panel
- 2.10. Display Content in an Expander
- 2.11. Place a Group Box Around a Set of UI Elements
- 2.12. Display a Message Box
- 2.13. Display a Pop-up Window
- 2.14. Display a Border
- 2.15. Display a Menu
- 2.16. Display a Toolbar
- 2.17. Display a Status Bar
- 2.18. Control the Size of UI Elements in a Form
- 2.19. Define the Tab Order of UI Elements in a Form
-
3. Using Standard Controls
- 3.1. Display Control Content Surrounded by Braces
- 3.2. Display Simple Text
- 3.3. Display a Static Image
- 3.4. Get Simple Text Input from a User
- 3.5. Get Rich Text Input from a User
- 3.6. Load or Save the Content of a RichTextBox
- 3.7. Display a Password Entry Box
- 3.8. Spell Check a TextBox or RichTextBox Control in Real Time
- 3.9. Handle a Button Click
- 3.10. Generate Click Events Repeatedly While a Button Is Clicked
- 3.11. Set a Default Button
- 3.12. Provide Quick Keyboard Access to Text Boxes
- 3.13. Provide Quick Keyboard Access to Buttons
- 3.14. Get User Input from a Slider
- 3.15. Display a Context Menu
- 3.16. Display a Tool Tip on a Control
- 3.17. Display a Tool Tip on a Disabled Control
- 3.18. Control the Display Duration and Position of a Tool Tip
- 3.19. View and Select Items from a Set of Radio Buttons
- 3.20. View and Select Items from a Set of Check Boxes
- 3.21. View and Select Items Using a Tree
- 3.22. View and Select Items Using a List
- 3.23. Dynamically Add Items to a List
- 3.24. View and Select Items Using a Combo Box
- 3.25. Display a Control Rotated
-
4. Creating User and Custom Controls
- 4.1. Create a User Control
- 4.2. Set the Content Property of a User Control
- 4.3. Add Properties to a User Control
- 4.4. Add Events to a User Control
- 4.5. Support Application Commands in a User Control
- 4.6. Add Custom Commands to a User Control
- 4.7. Set Design Mode Behavior in a User Control
- 4.8. Create a Lookless Custom Control
- 4.9. Specify the Parts Required by a Custom Control
- 4.10. Support UI Automation in a Custom Control
- 4.11. Create a Custom-Drawn Element
- 4.12. Create a Numeric TextBox Control
- 4.13. Create a Scrollable Canvas Control
- 4.14. Create a Zoomable Canvas Control
- 4.15. Create a Drag Canvas Control
-
5. Data Binding
- 5.1. Bind to a Property of a UI Element
- 5.2. Create a Two-Way Binding
- 5.3. Bind a Property of an Element to Itself
- 5.4. Bind to CLR Objects
- 5.5. Bind to an Existing Object Instance
- 5.6. Bind to XML Data
- 5.7. Bind to a Method
- 5.8. Bind to a Command
- 5.9. Bind to the Values of an Enumeration
- 5.10. Specify a Default Value for a Binding
- 5.11. Use Data Templates to Display Bound Data
- 5.12. Use Value Converters to Convert Bound Data
- 5.13. Use Data Triggers to Change the Appearance of Bound Data
- 5.14. Select a DataTemplate Based on Properties of the Data Object
- 5.15. Specify Validation Rules for a Binding
- 5.16. Bind to IDataErrorInfo
- 5.17. Bind to a Collection with the Master-Detail Pattern
- 5.18. Sort Data in a Collection
- 5.19. Apply Custom Sorting Logic to a Collection
- 5.20. Filter Data in a Collection
- 5.21. Group Data in a Collection
- 5.22. Apply Custom Grouping to a Collection
- 5.23. Bind to Application Settings
- 5.24. Bind to Application Resource Strings
-
6. Working with Styles, Templates, Skins, and Themes
- 6.1. Create a Named Style
- 6.2. Create a Typed Style
- 6.3. Override Style Properties
- 6.4. Inherit from a Common Base Style
- 6.5. Change a Control's Appearance on Mouse Over
- 6.6. Apply Multiple Triggers to the Same Element
- 6.7. Evaluate Multiple Properties for the Same Trigger
- 6.8. Programmatically Extract an Element's Style
- 6.9. Set a Style Programmatically
- 6.10. Ignore an Implicit Style
- 6.11. Change the Appearance of Alternate Items in a List
- 6.12. Change the Appearance of a List Item When It's Selected
- 6.13. Create a Control Template
- 6.14. Put a Control Template into a Style
- 6.15. Create a Control Template That Can Be Customized by Properties
- 6.16. Specify Named Parts of a Control Template
- 6.17. Find ControlTemplate-Generated Elements
- 6.18. Create a Custom ToolTip Style
- 6.19. Dynamically Change the Skin of an Application
- 6.20. Create Styles That Adapt to the Current OS Theme
-
7. Working with Text, Documents, and Printing
- 7.1. Programmatically Insert Text into a RichTextBox
- 7.2. Apply Syntax Highlighting in a Text Control
- 7.3. Print a WPF Visual
- 7.4. Print a Collection of WPF Visuals
- 7.5. Configure Printing Options Using a PrintTicket
- 7.6. Print a Simple Document
- 7.7. Asynchronously Print a Multipage FixedDocument
- 7.8. Programmatically Create and Save a Simple FixedDocument
- 7.9. Use Figures and Floaters in a FlowDocument
- 7.10. Programmatically Create and Save a FlowDocument
- 7.11. Asynchronously Save a FixedDocument to an XPS File
- 7.12. Display a Document
- 7.13. Annotate a Document with Sticky Notes
- 7.14. Use Highlighting in a Document
- 7.15. Load and Save User-Defined Annotations
- 7.16. Print a Document's Annotations
-
8. Multithreading
- 8.1. Execute a Method Asynchronously Using the Dispatcher Queue
- 8.2. Load the Data for a Window Asynchronously After It Has Rendered
- 8.3. Load the Items in a ListBox Asynchronously
- 8.4. Check Whether You Are Running on the UI Thread
- 8.5. Ensure That You Are Running on the UI Thread
- 8.6. Execute a Method Asynchronously Using a Background Worker Thread
- 8.7. Track the Progress of a Background Worker Thread
- 8.8. Support the Cancellation of a Background Worker Thread
- 8.9. Create a Background Worker Thread in XAML
- 8.10. Update the UI Asynchronously on a Timer
- 8.11. Show a Continuous Animation During an Asynchronous Process
- 8.12. Show a ProgressBar While Processing on a Background Thread
- 8.13. Show a Cancellable ProgressBar While Processing on a Background Thread
- 8.14. Show a Continuous Progress Bar While Processing on a Background Thread
- 8.15. Implement Application.DoEvents in WPF
- 8.16. Create a Separate Thread for Each Window in a Multiwindow Application
-
9. Working with 2D Graphics
- 9.1. Draw a Line
- 9.2. Draw a Sequence of Connected Lines
- 9.3. Format Lines
- 9.4. Draw a Curved Line
- 9.5. Draw Simple Shapes
- 9.6. Draw Complex Shapes
- 9.7. Create Reusable Shapes
- 9.8. Display a Tool Tip on a Shape
- 9.9. Display Graphics Elements in a Tool Tip
- 9.10. Use System Colors in Your Graphics
- 9.11. Draw or Fill a Shape Using a Solid Color
- 9.12. Fill a Shape with a Linear or Radial Color Gradient
- 9.13. Fill a Shape with an Image
- 9.14. Fill a Shape with a Pattern or Texture
- 9.15. Fill a Shape with a View of Active UI Elements
- 9.16. Apply Blur Effects on UI Elements
- 9.17. Apply a Glow Effect to Your UI Elements
- 9.18. Apply a Drop Shadow Effect to Your UI Elements
- 9.19. Scale, Skew, Rotate, or Position Graphics Elements
- 10. Working with 3D Graphics
-
11. Creating Animation
- 11.1. Animate the Property of a Control
- 11.2. Animate a Property of a Control Set with a Data Binding
- 11.3. Remove Animations
- 11.4. Overlap Animations
- 11.5. Animate Several Properties in Parallel
- 11.6. Create a Keyframe-Based Animation
- 11.7. Control the Progress of an Animation
- 11.8. Animate the Shape of a Path
- 11.9. Loop and Reverse an Animation
- 11.10. Limit the Frame Rate of a Storyboard
- 11.11. Limit the Frame Rate for All Animations in an Application
- 11.12. Animate an Object Along a Path
- 11.13. Play Back Audio or Video with a MediaTimeline
- 11.14. Synchronize Timeline Animations with a MediaTimeline
- 11.15. Receive Notification When an Animation Completes
- 11.16. Animate the Color of a Brush with Indirect Property Targeting
- 11.17. Control Animations Through Triggers
- 11.18. Animate Text
-
12. Dealing with Multimedia and User Input
- 12.1. Play System Sounds
- 12.2. Use Triggers to Play Audio When a User Interacts with a Control
- 12.3. Play a Media File
- 12.4. Respond When the User Clicks a UI Element with the Mouse
- 12.5. Respond When the User Clicks a UI Element in a Container with the Mouse
- 12.6. Respond When the User Rotates the Mouse Wheel
- 12.7. Drag Items from a List and Drop Them on a Canvas
- 12.8. Handle Keyboard Events
- 12.9. Query Keyboard State
- 12.10. Suppress Keyboard and Mouse Events
- 13. Migrating and Windows Forms Interoperability
Product information
- Title: WPF Recipes in C# 2008: A Problem-Solution Approach
- Author(s):
- Release date: September 2008
- Publisher(s): Apress
- ISBN: 9781430210849
You might also like
book
WPF in Action with Visual Studio 2008
The combination of WPF and Visual Studio 2008 represents the start of the next generation of …
book
WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4
Build effective user interfaces with Windows Presentation Foundation Windows Presentation Foundation (WPF) is included with the …
book
Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition
The Microsoft Windows Presentation Foundation provides the foundation for building applications and high-quality user experiences in …
book
Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4
This book shows you how WPF really works. It provides you with the no-nonsense, practical advice …