RelativeSource Property

Binding.RelativeSource Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

Namespace:  System.Windows.Data
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

'Declaration
Public Property RelativeSource As RelativeSource
<Binding RelativeSource="{RelativeSource TemplatedParent}"/>
-or-
<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: System.Windows.Data.RelativeSource
The relative location of the binding source to use. The default is Nothing.

ExceptionCondition
InvalidOperationException

The Binding has already been attached to a target element, and cannot be modified.

-or-

The ElementName or Source property has already been set.

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 theRelativeSource markup extension.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft