This documentation is archived and is not being maintained.

RelativeSource MarkupExtension

Specifies properties of a RelativeSource binding source, to be used within a Binding Markup Extension, or when setting the RelativeSource property of a Binding element established in XAML.

<Binding RelativeSource="{RelativeSource modeEnumValue}" .../>

<object property="{Binding RelativeSource={RelativeSource modeEnumValue} ...}" .../>

    <RelativeSource Mode="modeEnumValue"/>
- or 
      AncestorType="{x:Type typeName}"


One of the following:


The string token FindAncestor. Using this token enters a mode whereby a RelativeSource specifies an ancestor type and optionally an ancestor level. This corresponds to a RelativeSource as created with its Mode property set to FindAncestor.


Required for FindAncestor mode. The name of a type, which fills the AncestorType property.


Optional for FindAncestor mode. An ancestor level (evaluated towards the parent direction in the logical tree).

In the object element syntax for FindAncestor mode shown above, the second object element syntax is used specifically for FindAncestor mode. FindAncestor mode requires an AncestorType value. You must set AncestorType as an attribute using an x:Type Markup Extension reference to the type of ancestor to look for. The AncestorType value is used when the binding request is processed at run-time.

For FindAncestor mode, the optional property AncestorLevel can help disambiguate the ancestor lookup in cases where there is possibly more than one ancestor of that type existing in the element tree.

For more details on using the FindAncestor mode, see RelativeSource

Describing data binding as a concept is not covered here, see Data Binding Overview.

In the WPF XAML processor implementation, the handling for this markup extension is defined by the RelativeSource class.

RelativeSource is a markup extension. Markup extensions are typically implemented when there is a requirement to escape attribute values to be other than literal values or handler names, and the requirement is more global than just putting type converters on certain types or properties. All markup extensions in XAML use the { and } characters in their attribute syntax, which is the convention by which a XAML processor recognizes that a markup extension must process the attribute. For more information, see Markup Extensions and XAML.