Binding.Source Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the object to use as the binding source.
public:
property System::Object ^ Source { System::Object ^ get(); void set(System::Object ^ value); };
public object Source { get; set; }
member this.Source : obj with get, set
Public Property Source As Object
Property Value
The object to use as the binding source.
Examples
The following example uses a Person object with a string property named PersonName that is defined in the SDKSample namespace, as the first highlighted line shows. In the highlighted line that contains the element, it instantiates the Person object with a PersonName property value of Joe. This is done in the Resources section and assigned an x:Key.
The highlighted line that contains the elements shows how to bind to the PersonName property. As a result, the TextBlock control appears with the value "Joe".
In the following example, the Source values of the Binding objects are set to the static property Application.Current:
Remarks
By default, bindings inherit the data context specified by the DataContext property, if one has been set. However, the Source 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 Source 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, Source, 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.
XAML Attribute Usage
XAML Values
object An existing object. To refer to an existing object, use the StaticResource Markup Extension