FrameworkContentElement::DataContext Property
Gets or sets the data context for an element when it participates in data binding.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[LocalizabilityAttribute(LocalizationCategory::NeverLocalize)] public: property Object^ DataContext { Object^ get (); void set (Object^ value); }
<object> <object.DataContext> <dataContextObject /> </object.DataContext> </object>
<object DataContext="bindingUsage"/> - or - <object DataContext="{resourceExtension contextResourceKey}"/>
XAML Values
Data context is a concept that allows elements to inherit information from their parent elements about the binding source that is used for binding, as well as other characteristics of the binding such as the path.
Data context can be set directly to a common language runtime (CLR) object, with the bindings evaluating to properties of that object. Alternatively, you can set the data context to a DataSourceProvider object.
This dependency property inherits property values. If there are child elements with no other value for DataContext established through local values or styles, the property system will set the value to be the DataContext value of the nearest parent element with this value assigned.
Alternatively, you can use one of the following properties of the Binding class to specify the binding source explicitly: ElementName, Source, or RelativeSource. For more information, see How to: Specify the Binding Source.
In XAML, DataContext is most commonly set to as a Binding declaration. You can use either property element syntax or attribute syntax. Attribute syntax is shown in the example on this page. You can also set DataContext in code.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.