The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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 Self; corresponds to a RelativeSource as created with its Mode property set to Self.

  • The string token TemplatedParent; corresponds to a RelativeSource as created with its Mode property set to TemplatedParent.

  • The string token PreviousData; corresponds to a RelativeSource as created with its Mode property set to PreviousData.

  • See below for information on FindAncestor mode.


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. 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 reader implementation, the handling for this markup extension is defined by the TypeExtension 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 reader recognizes that a markup extension must process the attribute. For more information, see Markup Extensions and XAML.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft