.NET Framework Class Library for Silverlight
Binding..::.RelativeSource Property

[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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)
Syntax

Visual Basic (Declaration)
Public Property RelativeSource As RelativeSource
    Get
    Set
Visual Basic (Usage)
Dim instance As Binding
Dim value As RelativeSource

value = instance.RelativeSource

instance.RelativeSource = value
C#
public RelativeSource RelativeSource { get; set; }
XAML Attribute Usage
<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

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.

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

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Other Resources

Page view tracker