The Windows Presentation Foundation (WPF) framework allows you to develop desktop applications with amazing graphic capabilities, but it does not stop there. An application needs to display data of some sort and connecting UIElements to underlying data structures needs to be flexible. That is where DataContext comes into play.

DataContext works hand-in-hand with data binding to provide hierarchical data presentation. It is what connects the front end to the code-behind and enables changes made to data in the user interface to update the data source, and conversely, while maintaining the order of your data structure. You’ll see examples of this in the case study project for this post.

This tutorial will guide you through building a WPF application where you can explore DataContext at work. You will create a data dashboard that visualizes data from different simulated sources.

Prerequisites

You’ll need the following tools and resources to build and run this project:

Windows 10 – It puts the Windows in Windows Presentation Foundation.

.NET Core SDK 3.1 – The SDK includes the APIs, runtime, and CLI.

Visual Studio 2019 with the following workloads and individual components:

  • .NET desktop development workload (Includes C#)
  • GitHub Extension for Visual Studio (If you want to clone the companion repository.)

You should have a general knowledge of Visual Studio and the C## language syntax. You will be adding and editing files, and debugging code.

There is a companion repositoryfor this post available on GitHub. It contains the complete source code for the tutorial project. The code uses the dependency injection features of .NET Core, but you won’t need extensive knowledge of it to understand the WPF features that are the focus of this post

#code #tutorials and hacks #data-analysis

Understanding Windows Presentation Foundation (WPF) Data Binding
1.20 GEEK