Purpose of the Binding Extension
The {Binding} markup extension connects a target property on a UI element to a source property, typically on a data context object, so that the UI reflects the underlying data and, in TwoWay mode, pushes UI changes back to the source. It is the backbone of the MVVM pattern: a Button's IsEnabled might bind to CanSave on a view model, and a TextBox's Text might bind to a Customer.Name property, all without any imperative code wiring the two together.
Cricket analogy: It is like a scoreboard operator watching the umpire's signals and updating the display the instant a boundary is signaled, without anyone manually typing the new score, just as {Binding} keeps a TextBlock in sync with a changing source property.
Common Binding Properties: Path, Mode, and Source
Path specifies which property on the source object to read, and can include nested navigation like Path=Customer.Address.City or indexer syntax like Path=Items[0]. Mode controls the direction of data flow: OneWay pushes source-to-target only, TwoWay pushes both directions, OneWayToSource pushes target-to-source only, and OneTime reads the value once and never updates again. Source, ElementName, and RelativeSource control where the binding looks for its data: Source points to an arbitrary object, ElementName binds to another named element in the same XAML tree, and RelativeSource can target an ancestor via FindAncestor or the templated parent via TemplatedParent.
Cricket analogy: It is like a scoring path in cricket that drills down from 'team' to 'innings' to 'batter' to 'runs', analogous to Path=Customer.Address.City drilling through nested objects to reach a leaf property.
<!-- TwoWay binding with nested path and a converter -->
<TextBox Text="{Binding Path=Customer.Address.City, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
<!-- Binding to a sibling element by name -->
<Slider x:Name="VolumeSlider" Minimum="0" Maximum="100" />
<TextBlock Text="{Binding ElementName=VolumeSlider, Path=Value}" />
<!-- Binding relative to an ancestor in the visual tree -->
<TextBlock Text="{Binding RelativeSource={RelativeSource
AncestorType={x:Type Window}}, Path=Title}" />For a TwoWay or OneWay binding to update automatically after the initial load, the source object must implement INotifyPropertyChanged and raise PropertyChanged for the bound property. Without it, the target will show the correct initial value but silently stop updating when the source changes later.
- {Binding} links a target property to a source property, enabling declarative, code-free UI synchronization.
- Path supports nested navigation (Customer.Address.City) and indexers (Items[0]).
- Mode controls data-flow direction: OneWay, TwoWay, OneWayToSource, and OneTime.
- Source, ElementName, and RelativeSource determine where the binding looks up its data.
- RelativeSource AncestorType finds a bound value from a parent in the visual tree; TemplatedParent binds inside a control template.
- UpdateSourceTrigger controls when a TwoWay binding pushes target changes back, e.g. PropertyChanged vs LostFocus.
- The source object must implement INotifyPropertyChanged for live updates after the initial render.
Practice what you learned
1. Which Binding Mode value both reads from and writes to the source property?
2. What must a source object implement for a OneWay or TwoWay binding to update the UI after the initial load?
3. Which Binding property lets you bind to a named element elsewhere in the same XAML tree?
4. What does Path=Items[0] indicate in a Binding?
5. Which RelativeSource mode is typically used inside a ControlTemplate to bind back to the control being templated?
Was this page helpful?
You May Also Like
Markup Extensions Overview
How XAML's curly-brace syntax defers value creation to parse time through classes that implement MarkupExtension.
TemplateBinding
The lightweight, one-way markup extension used inside a ControlTemplate to connect template visuals to the templated control's own properties.
StaticResource and DynamicResource
The difference between resolving a resource once at parse time versus keeping a live, updating reference to it.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics
Microsoft TechnologiesMVVM Design Pattern Study Notes
.NET · 30 topics