แก้ไข

แชร์ผ่าน


Binding.ElementName Property

Definition

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

public:
 property System::String ^ ElementName { System::String ^ get(); void set(System::String ^ value); };
public string ElementName { get; set; }
member this.ElementName : string with get, set
Public Property ElementName As String

Property Value

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.

Remarks

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.

Applies to