Windows Presentation Foundation Development Cookbook

Book description

Gain comprehensive insight into WPF mechanics and capabilities.

About This Book

  • Gain a strong foundation in WPF features and patterns
  • Leverage the MVVM pattern to build decoupled, maintainable apps
  • Increase efficiency through Performance tuning and UI automation

Who This Book Is For

The book is intended for developers who are relatively new to WPF (Windows Presentation Foundation), or those who have been working with WPF for some time, but want to get a deeper understanding of its foundation and concepts to gain practical knowledge. Basic knowledge of C# and Visual Studio is assumed.

What You Will Learn

  • Understand the fundamentals of WPF
  • Explore the major controls and manage element layout
  • Implement data binding
  • Create custom elements that lead to a particular implementation path
  • Customize controls, styles, and templates in XAML
  • Leverage the MVVM pattern to maintain a clean and reusable structure in your code
  • Master practical animations
  • Integrate WCF services in a WPF application
  • Implement WPFs support for debugging and asynchronous operations

In Detail

Windows Presentation Foundation (WPF) is Microsoft's development tool for building rich Windows client user experiences that incorporate UIs, media, and documents. With the updates in .NET 4.7, Visual Studio 2017, C# 7, and .NET Standard 2.0, WPF has taken giant strides and is now easier than ever for developers to use.

If you want to get an in-depth view of WPF mechanics and capabilities, then this book is for you.

The book begins by teaching you about the fundamentals of WPF and then quickly shows you the standard controls and the layout options. It teaches you about data bindings and how to utilize resources and the MVVM pattern to maintain a clean and reusable structure in your code. After this, you will explore the animation capabilities of WPF and see how they integrate with other mechanisms. Towards the end of the book, you will learn about WCF services and explore WPF's support for debugging and asynchronous operations.

By the end of the book, you will have a deep understanding of WPF and will know how to build resilient applications.

Style and approach

This book takes a recipe-based approach to teaching you how to create fault-tolerant WPF applications.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Windows Presentation Foundation Development Cookbook
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. WPF Fundamentals
    1. Introduction
    2. The WPF Architecture
    3. Presentation Framework
    4. Presentation Core
    5. Common Language Runtime
    6. Media Integration Library
    7. OS Core
    8. Types of WPF applications
    9. The XAML overview
    10. XAML syntax terminologies
    11. Object element syntax
    12. Property Attribute syntax
    13. Property Element syntax
    14. Content syntax
    15. Collection syntax
    16. Event Attribute syntax
    17. Installing WPF Workload with Visual Studio 2017
    18. Getting ready
    19. How to do it...
    20. Creating WPF applications
    21. Getting ready
    22. How to do it...
    23. There's more...
    24. Creating and navigating from one window to another
    25. Getting ready
    26. How to do it...
    27. How it works...
    28. There's more...
    29. Creating and navigating from one page to another
    30. Getting ready
    31. How to do it...
    32. How it works...
    33. There's more...
    34. Creating a dialog box
    35. Getting ready
    36. How to do it...
    37. How it works...
    38. There's more...
    39. Using the open file dialog
    40. Using the save file dialog
    41. Using the print dialog
    42. Other common dialogs
    43. Creating ownership between windows
    44. Getting ready
    45. How to do it...
    46. How it works...
    47. There's more...
    48. Creating a single instance application
    49. Getting ready
    50. How to do it...
    51. How it works...
    52. There's more...
    53. Passing arguments to WPF applications
    54. Getting ready
    55. How to do it...
    56. How it works...
    57. There's more...
    58. Handling unhandled exceptions
    59. Getting ready
    60. How to do it...
    61. How it works...
    62. There's more...
  7. Using WPF Standard Controls
    1. Introduction
    2. Using the TextBlock control to add plain text
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. Using Label to add other controls in text
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. There's more...
    12. Providing a user option to input text
    13. Getting ready
    14. How to do it...
    15. How it works...
    16. There's more...
    17. Windows Clipboard support
    18. Adding spellcheck support
    19. Adding images to your application UI
    20. Getting ready
    21. How to do it...
    22. How it works...
    23. There's more...
    24. Working with ready-to-use 2D shapes
    25. Getting ready
    26. How to do it...
    27. How it works...
    28. There's more...
    29. Adding tooltips to show additional information
    30. Getting ready
    31. How to do it...
    32. How it works...
    33. There's more...
    34. Adding a standard menu to the WPF application
    35. Getting ready
    36. How to do it...
    37. How it works...
    38. There's more...
    39. Adding an access key to menus
    40. Adding icons to menus
    41. Adding checkable menu items
    42. Adding click-event handlers to menus
    43. Providing extra functionalities using the context menu
    44. Getting ready
    45. How to do it...
    46. How it works...
    47. Adding user options with radio buttons and checkboxes
    48. Getting ready
    49. How to do it...
    50. How it works...
    51. There's more...
    52. Working with the progress bar control
    53. Getting ready
    54. How to do it...
    55. How it works...
    56. Using the Slider control to pick a numeric value
    57. Getting ready
    58. How to do it...
    59. How it works...
    60. There's more...
    61. Using the Calendar control in your application
    62. Getting ready
    63. How to do it...
    64. How it works...
    65. There's more...
    66. The SelectionModes property
    67. The DisplayDate property
    68. The DisplayMode property
    69. The BlackoutDates property
    70. Listing items in a Listbox control
    71. Getting ready
    72. How to do it...
    73. How it works...
    74. There's more...
    75. Implementing multi selection
    76. Customizing the ListBoxItem with multiple controls
    77. Providing options to select from a ComboBox
    78. Getting ready
    79. How to do it...
    80. How it works...
    81. There's more...
    82. Adding a status bar to your window
    83. Getting ready
    84. How to do it...
    85. How it works...
    86. Adding a toolbar panel to perform quick tasks
    87. Getting ready
    88. How to do it...
    89. How it works...
  8. Layouts and Panels
    1. Introduction
    2. Building a UI layout using a Grid
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. Creating a resizable Grid
    8. Spanning elements across multiple rows and/or columns
    9. Placing elements in uniform cells
    10. Getting ready
    11. How to do it...
    12. How it works...
    13. There's more...
    14. Setting the row and column count
    15. Defining the first cell of the UniformGrid
    16. Filling elements from right to left
    17. Automatically repositioning controls using WrapPanel
    18. Getting ready
    19. How to do it...
    20. How it works...
    21. There's more...
    22. Placing controls in a Stack
    23. Getting ready
    24. How to do it...
    25. How it works...
    26. There's more...
    27. Positioning controls inside a Canvas
    28. Getting ready
    29. How to do it...
    30. How it works...
    31. There's more...
    32. Wrapping UI elements using a Border
    33. Getting ready
    34. How to do it...
    35. How it works...
    36. Creating a scrollable panel
    37. Getting ready
    38. How to do it...
    39. How it works...
    40. Docking controls using the DockPanel
    41. Getting ready
    42. How to do it...
    43. How it works...
    44. There's more...
    45. Rescaling UI elements using a ViewBox
    46. Getting ready
    47. How to do it...
    48. How it works...
    49. There's more...
    50. Creating a tabbed layout
    51. Getting ready
    52. How to do it...
    53. How it works...
    54. Dynamically adding/removing elements in a panel
    55. Getting ready
    56. How to do it...
    57. How it works...
    58. There's more...
    59. Implementing the drag and drop feature
    60. Getting ready
    61. How to do it...
    62. How it works...
    63. There's more...
  9. Working with Data Bindings
    1. Introduction
    2. Working with CLR properties and UI notifications
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. Working with dependency properties
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. There's more...
    12. Working with attached properties
    13. Getting ready
    14. How to do it...
    15. How it works...
    16. Data binding to an object
    17. Getting ready
    18. How to do it...
    19. How it works...
    20. Data binding to a collection
    21. Getting ready
    22. How to do it...
    23. How it works...
    24. There's more...
    25. Element-to-element data binding
    26. Getting ready
    27. How to do it...
    28. How it works...
    29. Sorting data in a DataGrid control
    30. Getting ready
    31. How to do it...
    32. How it works...
    33. Grouping data in a DataGrid control
    34. Getting ready
    35. How to do it...
    36. How it works...
    37. There's more...
    38. Filtering data in a DataGrid control
    39. Getting ready
    40. How to do it...
    41. How it works...
    42. Using static bindings
    43. Getting ready
    44. How to do it...
    45. How it works...
    46. Using value converters
    47. Getting ready
    48. How to do it...
    49. How it works...
    50. There's more...
    51. Using multi-value converters
    52. Getting ready
    53. How to do it...
    54. How it works...
  10. Using Custom Controls and User Controls
    1. Introduction
    2. Creating a custom control
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. XMLNS attribute declaration
    8. Default styling
    9. Toolbox integration
    10. Customizing the template of a custom control
    11. Getting ready
    12. How to do it...
    13. How it works...
    14. Exposing properties from the custom control
    15. Getting ready
    16. How to do it...
    17. How it works...
    18. Exposing events from a custom control
    19. Getting ready
    20. How to do it...
    21. How it works...
    22. Extending the functionality of a control using behavior
    23. Getting ready
    24. How to do it...
    25. How it works...
    26. Creating a User Control interface
    27. Getting ready
    28. How to do it...
    29. How it works...
    30. Exposing events from a User Control
    31. Getting ready
    32. How to do it...
    33. How it works...
    34. Customizing the XMLNS namespace
    35. Getting ready
    36. How to do it...
    37. How it works...
  11. Using Styles, Templates, and Triggers
    1. Introduction
    2. Creating the style of a control
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. Creating the Style of a control based on another Style
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. Applying Style to a control automatically
    12. Getting ready
    13. How to do it...
    14. How it works...
    15. Editing the template of any control
    16. Getting ready
    17. How to do it...
    18. How it works...
    19. There's more...
    20. Creating a property trigger
    21. Getting ready
    22. How to do it...
    23. How it works...
    24. Creating a multi trigger
    25. Getting ready
    26. How to do it...
    27. How it works...
    28. Creating a data trigger
    29. Getting ready
    30. How to do it...
    31. How it works...
    32. Creating a multi data trigger
    33. Getting ready
    34. How to do it...
    35. How it works...
    36. Creating an event trigger
    37. Getting ready
    38. How to do it...
    39. How it works...
  12. Using Resources and MVVM Patterns
    1. Introduction
    2. Using binary resources inside a WPF application
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. Using binary resources from another assembly
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. There's more...
    12. Accessing binary resources in code
    13. Getting ready
    14. How to do it...
    15. How it works...
    16. Using static logical resources in WPF
    17. Getting ready
    18. How to do it...
    19. How it works...
    20. There's more...
    21. Using dynamic logical resources in WPF
    22. Getting ready
    23. How to do it...
    24. How it works...
    25. There's more...
    26. Managing logical resources
    27. Getting ready
    28. How to do it...
    29. How it works...
    30. There's more...
    31. Using user selected colors and fonts
    32. Getting ready
    33. How to do it...
    34. How it works...
    35. There's more...
    36. Building an application using the MVVM pattern
    37. Getting ready
    38. How to do it...
    39. How it works...
    40. Using routed commands in a WPF application
    41. Getting ready
    42. How to do it...
    43. How it works...
  13. Working with Animations
    1. Introduction
    2. Scaling an element while rendering
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. Rotating an element while rendering
    7. Getting ready
    8. How to do it...
    9. How it works...
    10. Skewing an element while rendering
    11. Getting ready
    12. How to do it...
    13. How it works...
    14. Moving an element while rendering
    15. Getting ready
    16. How to do it...
    17. How it works...
    18. Grouping multiple transforms
    19. Getting ready
    20. How to do it...
    21. How it works...
    22. There's more...
    23. Creating property-based animations
    24. Getting ready
    25. How to do it...
    26. How it works...
    27. Creating path-based animations
    28. Getting ready
    29. How to do it...
    30. How it works...
    31. Creating key-frame-based animations
    32. Getting ready
    33. How to do it...
    34. How it works...
    35. There's more...
    36. Adding easing effects to animations
    37. Getting ready
    38. How to do it...
    39. How it works...
    40. There's more...
    41. BounceEase
    42. CircleEase
    43. CubicEase
    44. ElasticEase
    45. ExponentialEase
    46. PowerEase
    47. QuadraticEase
    48. QuarticEase
    49. QuinticEase
    50. SineEase
  14. Using WCF Services
    1. Introduction
    2. Creating a WCF service
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. The DataContract attribute
    7. The DataMember attribute
    8. The ServiceContract attribute
    9. The OperationContract attribute
    10. Self-hosting a WCF service
    11. Getting ready
    12. How to do it...
    13. How it works...
    14. There's more...
    15. Hosting a WCF service in an IIS server
    16. Getting ready
    17. How to do it...
    18. How it works...
    19. Integrating a WCF service in a WPF application
    20. Getting ready
    21. How to do it...
    22. How it works...
    23. There's more...
  15. Debugging and Threading
    1. Introduction
    2. Enabling the UI debugging tool for XAML
    3. Getting ready
    4. How to do it...
    5. Navigating through XAML elements using Live Visual Tree
    6. Getting ready
    7. How to do it...
    8. How it works...
    9. There's more...
    10. Inspecting XAML properties using Live Property Explorer
    11. Getting ready
    12. How to do it...
    13. How it works...
    14. There's more...
    15. Updating the UI from a non-UI thread
    16. Getting ready
    17. How to do it...
    18. How it works...
    19. There's more...
    20. Adding cancelation support to long running threads
    21. Getting ready
    22. How to do it...
    23. How it works...
    24. Using the background worker component
    25. Getting ready
    26. How to do it...
    27. How it works...
    28. There's more...
    29. Using a timer to periodically update the UI
    30. Getting ready
    31. How to do it...
    32. How it works...
  16. Interoperability with Win32 and WinForm
    1. Introduction
    2. Hosting WinForm controls in WPF applications
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. Hosting WPF controls in WinForm applications
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. Calling Win32 APIs from WPF applications
    12. Getting ready
    13. How to do it...
    14. How it works...
    15. Embedding ActiveX controls in WPF applications
    16. Getting ready
    17. How to do it...
    18. How it works...
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Windows Presentation Foundation Development Cookbook
  • Author(s): Kunal Chowdhury
  • Release date: February 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788399807