Binding.ElementName Property

Gets or sets the name of the element to use as the binding source object.

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public string ElementName { get; set; }
<object ElementName="string" .../>

Property Value

Type: System.String
The value of the Name property or x:Name Directive of the element of interest. You can refer to elements in code only if they are registered to the appropriate NameScope through RegisterName. For more information, see WPF XAML Namescopes.
The default is null.

This property is useful when you want to bind to the property of another element in your application. For example, if you want to use a Slider to control the height of another control in your application, or if you want to bind the Content of your control to the SelectedValue property of your ListBox control.

By default, bindings inherit the data context specified by the DataContext property, if one has been set. However, the ElementName property is one of the ways you can explicitly set the source of a Binding and override the inherited data context. For more information, see How to: Specify the Binding Source.

The Source and RelativeSource properties of the Binding class also enable you to set the source of the binding explicitly. However, only one of the three properties, ElementName, Source, and RelativeSource, should be set for each binding, or a conflict might occur. This property throws an exception if there is a binding source conflict.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft