Binding.Source Property


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

 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.


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 <src> 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.

  Title="Simple Data Binding Sample">

    <src:Person x:Key="myDataSource" PersonName="Joe"/>
    <Style TargetType="{x:Type Label}">
      <Setter Property="DockPanel.Dock" Value="Top"/>
      <Setter Property="FontSize" Value="12"/>
    <Style TargetType="{x:Type TextBox}">
      <Setter Property="Width" Value="100"/>
      <Setter Property="Height" Value="25"/>
      <Setter Property="DockPanel.Dock" Value="Top"/>
    <Style TargetType="{x:Type TextBlock}">
      <Setter Property="Width" Value="100"/>
      <Setter Property="Height" Value="25"/>
      <Setter Property="DockPanel.Dock" Value="Top"/>
      <Setter Property="Padding" Value="3"/>
  <Border Margin="5" BorderBrush="Aqua" BorderThickness="1" Padding="8" CornerRadius="3">
    <DockPanel Width="200" Height="100" Margin="35">
      <Label>Enter a Name:</Label>
          <Binding Source="{StaticResource myDataSource}" Path="PersonName"
      <Label>The name you entered:</Label>
      <TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=PersonName}"/>

The highlighted line that contains the <TextBlock> 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:

    <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.


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

<object Source="object"/>  

XAML Values

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

Applies to