RelativeSource Constructors

Definition

Initializes a new instance of the RelativeSource class.

Overloads

RelativeSource()

Initializes a new instance of the RelativeSource class.

RelativeSource(RelativeSourceMode)

Initializes a new instance of the RelativeSource class with an initial mode.

RelativeSource(RelativeSourceMode, Type, Int32)

Initializes a new instance of the RelativeSource class with an initial mode and additional tree-walking qualifiers for finding the desired relative source.

RelativeSource()

Initializes a new instance of the RelativeSource class.

C#
public RelativeSource();

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

RelativeSource(RelativeSourceMode)

Initializes a new instance of the RelativeSource class with an initial mode.

C#
public RelativeSource(System.Windows.Data.RelativeSourceMode mode);

Parameters

mode
RelativeSourceMode

One of the RelativeSourceMode values.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

RelativeSource(RelativeSourceMode, Type, Int32)

Initializes a new instance of the RelativeSource class with an initial mode and additional tree-walking qualifiers for finding the desired relative source.

C#
public RelativeSource(System.Windows.Data.RelativeSourceMode mode, Type ancestorType, int ancestorLevel);

Parameters

mode
RelativeSourceMode

One of the RelativeSourceMode values. For this signature to be relevant, this should be FindAncestor.

ancestorType
Type

The Type of ancestor to look for.

ancestorLevel
Int32

The ordinal position of the desired ancestor among all ancestors of the given type.

Examples

The following returns the second ItemsControl encountered on the upward path starting at the target element of the binding.

C#
Binding myBinding = new Binding();
// Returns the second ItemsControl encountered on the upward path
// starting at the target element of the binding
myBinding.RelativeSource = new RelativeSource(
    RelativeSourceMode.FindAncestor, typeof(ItemsControl), 2);

Remarks

ancestorType and ancestorLevel have no relevance if given as parameters for a mode other than FindAncestor. Do not use this signature for the other RelativeSourceMode values.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10