Binding.RelativeSource Property

Gets or sets the binding source by specifying its location relative to the position of the binding target.

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

Public Property RelativeSource As RelativeSource
Dim instance As Binding
Dim value As RelativeSource

value = instance.RelativeSource

instance.RelativeSource = value
/** @property */
public RelativeSource get_RelativeSource ()

/** @property */
public void set_RelativeSource (RelativeSource value)

public function get RelativeSource () : RelativeSource

public function set RelativeSource (value : RelativeSource)

 For XAML information, see RelativeSource MarkupExtension. 

Property Value

A RelativeSource object specifying the relative location of the binding source to use. The default value is a null reference (Nothing in Visual Basic).

This property is commonly used to bind one property of an object to another property of the same object, or to define a binding in a style or template.

By default, bindings inherit the data context specified by the DataContext property, if one has been set. However, the RelativeSource property is one of the ways you can explicitly set the source of a Binding and override the inherited data context. For more information, see How to: Specify the Binding Source.

The Binding.ElementName and Binding.Source 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.

The following example shows a style trigger that creates a ToolTip that reports a validation error message. The value of the setter binds to the error content of the current TextBox (the TextBox using the style) using the RelativeSource property. For more information on this example, see Implement Binding Validation.

<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
    <Trigger Property="Validation.HasError" Value="true">
      <Setter Property="ToolTip"
        Value="{Binding RelativeSource={x:Static RelativeSource.Self},

To see the full example, see Binding Validation Sample.

More Code

How to: Create ListViewItems with a CheckBox

This example shows how to display a column of CheckBox controls in a ListView control that uses a GridView.

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions