WPF data binding lets you bind a target to a data source so the target automatically displays the value in the data source. For example, this lets you:
ListBox display an array of values defined in XAML code.
ListBox display a list of objects created in code-behind.
TreeView build a hierarchical display of objects created in code-behind.
TextBoxes, Labels, and other controls display additional detail about the currently selected item in a
ListBox, ComboBox, or
Additional WPF data-binding features let you sort, filter, and group data; let the user modify a control to update a data source; and validate changes to data.
This chapter provides an introduction to data binding in WPF. It explains how to use bindings to associate objects and how to use bindings to let a control use values supplied by other controls, XAML resources, and objects created in code-behind.
Data bindings have these four basic pieces:
Target — The object that will use the result of the binding
Target Property — The target object's property that will use the result
Source — The object that provides a value for the target object to use
Path — A path that locates the value within the source object
As a trivial example, suppose you want to bind a
Content property so that the
Label displays whatever you type in a
TextBox. If the
Label control is named
lblResult and the
TextBox is named
txtTypeHere, then you would need to create a binding ...