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.
Syntax
Public Property RelativeSource As RelativeSource
public RelativeSource RelativeSource { get; set; }
<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 nullNothingnullptra null reference (Nothing in Visual Basic).
Exceptions
| Exception | Condition |
|---|---|
| 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. |
Remarks
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.
Version Information
Windows Phone OS
Supported in: 8.1, 8.0, 7.1, 7.0
Platforms
Windows Phone
See Also
Reference
RelativeSource