Source Property

Binding.Source Property


Gets or sets the object to use as the binding source.

Namespace:   System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)

public object Source { get; set; }

Property Value

Type: System.Object

The object to use as the binding source.

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.

<object Source="object"/>


An existing object. To refer to an existing object, use the StaticResource Markup Extension

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.

Snippet section instantiation of code snippet {"project_id":"3fedad16-eaf1-41a6-8f96-0c1949c68f32","entity_id":"89bca917-b041-400f-a416-f9dfd47f2afc","entity_type":"CodeSnippet","locale":"en-US"} in source file ({"filename":"/CSharp/Page1.xaml","blob_type":"Source","blob_id":"-002fcsharp-002fpage1-002examl","blob_revision":2}) overlaps with other snippet sections. Ensure the tags are placed correctly.

To bind to the PersonName property you would do the following:

<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=PersonName}"/>

As a result, the TextBlock appears with the value "Joe".

In the following example, the Source values of the Binding objects are set to the static property Application.Current:

    <MultiBinding Converter="{StaticResource specialFeaturesConverter}">
        <Binding Path="CurrentUser.Rating" 
          Source="{x:Static Application.Current}"/>
        <Binding Path="CurrentUser.MemberSince" 
    Source="{x:Static Application.Current}"/>

For the full example, see Data Binding Demo.

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft