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 complete sample, see Simple Binding Sample.
For the full example, see Data Binding Demo.
|How to: Specify the Binding Source||In data binding, the binding source object refers to the object you obtain your data from. This topic describes the different ways of specifying the binding source.|
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.