Binding.ElementName Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Windows.Data
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property ElementName As String
public string ElementName { get; set; }
<Binding ElementName="nameString"/>

XAML Values

Property Value

Type: System.String
The value of the Name property or x:Name Attribute of the element to bind to. The default is nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
InvalidOperationException

The Binding has already been attached to a target element, and cannot be modified.

-or-

The Source or RelativeSource property has already been set.

Remarks

When you set this property, the specified value must refer to an element in one of the following locations:

  • The current XAML namescope.

  • The XAML namescope of the templated parent if the binding target is in a data template or control template.

For more information about namescopes, see XAML Namescopes.

Because of this restriction, you cannot use the ElementName property to bind to elements that are not created by using XAML. To bind to elements created programmatically, use the Source property instead.

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

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