Sharing the Source with DataContext

It’s common for many elements in the same user interface to bind to the same source object (different source properties, but the same source object). For this reason, Binding supports an implicit data source rather than explicitly marking every one with a Source, RelativeSource, or ElementName. This implicit data source is also known as a data context.

To designate a source object as a data context, you find a common parent element and set its DataContext property to the source object. (All FrameworkElements have this DataContext property of type Object.) When the system encounters a Binding without an explicit source object, it traverses up the element tree until it finds a non-null DataContext.

Therefore, ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.