Windows Dev Center

Binding.RelativeSource property

Gets or sets the binding source by specifying its location relative to the position of the binding target. This is most often used in bindings within XAML control templates.


Public Property RelativeSource As RelativeSource

<Binding RelativeSource="{RelativeSource TemplatedParent}"/>
<Binding RelativeSource="{RelativeSource Self}"/>

XAML Values

{RelativeSource TemplatedParent}

The control where a ControlTemplate is applied is the source for this binding. This is useful for applying validation error information in bindings at the template level.

{RelativeSource Self}

The target element should be used as the source for this binding. This is useful for binding one property of an element to another property on the same element.

Property value

Type: RelativeSource

The relative location of the binding source to use. The default is null.


Source, RelativeSource, and ElementName are mutually exclusive in a binding. If you have set one of these attributes, then setting either of the other two in a binding (through XAML or through code) will cause an exception. Setting RelativeSource in XAML always requires the use of the {RelativeSource} markup extension. This is also true if you are creating the entire binding as a {Binding} markup extension, in which case the {RelativeSource} markup extension is nested within the RelativeSource component of the expression.

You can't set the property values of a Binding object after that binding has been attached to a target element and target property. If you attempt this you'll get a run-time exception.


This XAML example is taken from the generic.xaml file that defines the default visual states for all XAML controls. This particular segment is one of the visual states for the ToggleSwitch control. Here, one of the animations defined by the visual state references properties of the control that exist specifically so that templates can access them and get run-time values that modify the animation. For the template XAML to get properties from the control where the template is applied, the binding must use {RelativeSource TemplatedParent} as the RelativeSource value.

<VisualStateGroup x:Name="ToggleStates">
    <VisualTransition x:Name="DraggingToOnTransition"
        <RepositionThemeAnimation TargetName="SwitchKnob" 
          {Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.KnobCurrentToOnOffset}"
        <RepositionThemeAnimation TargetName="SwitchCurtain"
          {Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.CurtainCurrentToOnOffset}"

Requirements (Windows 10 device family)

Device family


API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml::Data [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml::Data [C++]



See also

XAML data binding sample
Data binding in depth
{Binding} markup extension
{RelativeSource} markup extension



© 2015 Microsoft