Binding.ElementName property

This topic has not yet been rated - Rate this topic

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

Syntax


public string ElementName { get; set; }


<Binding ElementName="nameString"/>

XAML Values

nameString

The value of the Name property or x:Name attribute for the element of interest.

Property value

Type: System.String [.NET] | Platform::String [C++]

The value of the Name property or x:Name attribute for the element to bind to. The default is null.

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.
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.

Examples

The following code example demonstrates how to establish a two-way binding between a TextBox and a Slider control. For the complete code listing, see scenario 1 in the XAML data binding sample.


<Slider x:Name="slider1" Minimum="1" Maximum="100"/>
<TextBox Text="{Binding ElementName=slider1, Path=Value, Mode=TwoWay}"/>


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml.Data
Windows::UI::Xaml::Data [C++]

Metadata

Windows.winmd

See also

Binding
XAML data binding sample
Data binding overview

 

 

Build date: 12/4/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.