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.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Publisher Resources

Download Example Code

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
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. WPF Fundamentals
    1. Introduction
      1. The WPF Architecture
        1. Presentation Framework
        2. Presentation Core
        3. Common Language Runtime
        4. Media Integration Library
        5. OS Core
      2. Types of WPF applications
      3. The XAML overview
      4. XAML syntax terminologies
        1. Object element syntax
        2. Property Attribute syntax
        3. Property Element syntax
        4. Content syntax
        5. Collection syntax
        6. Event Attribute syntax
    2. Installing WPF Workload with Visual Studio 2017
      1. Getting ready
      2. How to do it...
    3. Creating WPF applications
      1. Getting ready
      2. How to do it...
      3. There's more...
    4. Creating and navigating from one window to another
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Creating and navigating from one page to another
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating a dialog box
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using the open file dialog
        2. Using the save file dialog
        3. Using the print dialog
        4. Other common dialogs
    7. Creating ownership between windows
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Creating a single instance application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Passing arguments to WPF applications
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Handling unhandled exceptions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  7. Using WPF Standard Controls
    1. Introduction
    2. Using the TextBlock control to add plain text
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using Label to add other controls in text
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Providing a user option to input text
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Windows Clipboard support
        2. Adding spellcheck support
    5. Adding images to your application UI
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Working with ready-to-use 2D shapes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Adding tooltips to show additional information
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Adding a standard menu to the WPF application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding an access key to menus
        2. Adding icons to menus
        3. Adding checkable menu items
        4. Adding click-event handlers to menus
    9. Providing extra functionalities using the context menu
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Adding user options with radio buttons and checkboxes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Working with the progress bar control
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Using the Slider control to pick a numeric value
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    13. Using the Calendar control in your application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. The SelectionModes property
        2. The DisplayDate property
        3. The DisplayMode property
        4. The BlackoutDates property
    14. Listing items in a Listbox control
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Implementing multi selection
        2. Customizing the ListBoxItem with multiple controls
    15. Providing options to select from a ComboBox
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    16. Adding a status bar to your window
      1. Getting ready
      2. How to do it...
      3. How it works...
    17. Adding a toolbar panel to perform quick tasks
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Layouts and Panels
    1. Introduction
    2. Building a UI layout using a Grid
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Creating a resizable Grid
        2. Spanning elements across multiple rows and/or columns
    3. Placing elements in uniform cells
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Setting the row and column count
        2. Defining the first cell of the UniformGrid
        3. Filling elements from right to left
    4. Automatically repositioning controls using WrapPanel
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Placing controls in a Stack
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Positioning controls inside a Canvas
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Wrapping UI elements using a Border
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a scrollable panel
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Docking controls using the DockPanel
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Rescaling UI elements using a ViewBox
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Creating a tabbed layout
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Dynamically adding/removing elements in a panel
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    13. Implementing the drag and drop feature
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Working with Data Bindings
    1. Introduction
    2. Working with CLR properties and UI notifications
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Working with dependency properties
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Working with attached properties
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Data binding to an object
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Data binding to a collection
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Element-to-element data binding
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Sorting data in a DataGrid control
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Grouping data in a DataGrid control
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Filtering data in a DataGrid control
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Using static bindings
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Using value converters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    13. Using multi-value converters
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Using Custom Controls and User Controls
    1. Introduction
    2. Creating a custom control
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. XMLNS attribute declaration
        2. Default styling
        3. Toolbox integration
    3. Customizing the template of a custom control
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Exposing properties from the custom control
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Exposing events from a custom control
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Extending the functionality of a control using behavior
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating a User Control interface
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Exposing events from a User Control
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Customizing the XMLNS namespace
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Using Styles, Templates, and Triggers
    1. Introduction
    2. Creating the style of a control
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Creating the Style of a control based on another Style
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Applying Style to a control automatically
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Editing the template of any control
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating a property trigger
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating a multi trigger
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a data trigger
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating a multi data trigger
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating an event trigger
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Using Resources and MVVM Patterns
    1. Introduction
    2. Using binary resources inside a WPF application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using binary resources from another assembly
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Accessing binary resources in code
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using static logical resources in WPF
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using dynamic logical resources in WPF
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Managing logical resources
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Using user selected colors and fonts
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Building an application using the MVVM pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Using routed commands in a WPF application
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Working with Animations
    1. Introduction
    2. Scaling an element while rendering
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Rotating an element while rendering
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Skewing an element while rendering
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Moving an element while rendering
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Grouping multiple transforms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Creating property-based animations
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating path-based animations
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating key-frame-based animations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Adding easing effects to animations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. BounceEase
        2. CircleEase
        3. CubicEase
        4. ElasticEase
        5. ExponentialEase
        6. PowerEase
        7. QuadraticEase
        8. QuarticEase
        9. QuinticEase
        10. SineEase
  14. Using WCF Services
    1. Introduction
    2. Creating a WCF service
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. The DataContract attribute
        2. The DataMember attribute
        3. The ServiceContract attribute
        4. The OperationContract attribute
    3. Self-hosting a WCF service
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Hosting a WCF service in an IIS server
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Integrating a WCF service in a WPF application
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  15. Debugging and Threading
    1. Introduction
    2. Enabling the UI debugging tool for XAML
      1. Getting ready
      2. How to do it...
    3. Navigating through XAML elements using Live Visual Tree
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Inspecting XAML properties using Live Property Explorer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Updating the UI from a non-UI thread
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Adding cancelation support to long running threads
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using the background worker component
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Using a timer to periodically update the UI
      1. Getting ready
      2. How to do it...
      3. How it works...
  16. Interoperability with Win32 and WinForm
    1. Introduction
    2. Hosting WinForm controls in WPF applications
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Hosting WPF controls in WinForm applications
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Calling Win32 APIs from WPF applications
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Embedding ActiveX controls in WPF applications
      1. Getting ready
      2. How to do it...
      3. 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