Gets or sets the object to use as the binding source.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
By default, bindings inherit the data context specified by the DataContext property, if one has been set. However, the property is one of the ways you can explicitly set the source of a Binding and override the inherited data context. If you do not need the functionality of establishing a scope in which several properties inherit the same data context, you can use the property instead of the DataContext property.
The Binding.ElementName and Binding.RelativeSource properties also enable you to set the source of the binding explicitly. However, only one of the three properties, ElementName, , and RelativeSource, should be set for each binding, or a conflict can occur. This property throws an exception if there is a binding source conflict.
To clear this property, set it to DependencyProperty.UnsetValue.
In this example, you have a Person object with a string property named PersonName. The Person object is defined in the namespace called SDKSample.
The following example instantiates the Person object with a PersonName property value of Joe. This is done in the Resources section and assigned an x:Key.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:SDKSample" SizeToContent="WidthAndHeight" Title="Simple Data Binding Sample"> <Window.Resources> <src:Person x:Key="myDataSource" PersonName="Joe"/> ... </Window.Resources> ... </Window>
To bind to the PersonName property you would do the following:
As a result, the TextBlock appears with the value "Joe".
For the full example, see Data Binding Demo.