AutomationProperties.LabeledBy Attached Property

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

Gets or sets the element that contains the text label for the element.

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

Syntax

'Declaration
See GetLabeledBy, SetLabeledBy
See GetLabeledBy, SetLabeledBy

XAML Values

  • labelElement
    The Name or x:Name of a control or text element that labels this control. Typically, this element is a Label or TextBlock.

Property Value

Type: System.Windows.UIElement
The element that contains the text label for the element.

Remarks

The most common way to set this attached property is through either an ElementName binding. An ElementName binding is a Binding declaration that specifies another element in the UI by name, passing that name to the ElementName attribute or property of the binding declaration. For more information, see ElementName, or Data Binding.

A TemplateBinding associates a value of the templated control with some property within the template's definition structure. This might be used if the templated control has a dedicated property for tracking label associations, something like the inverse relationship of Label.Target.

You could also use code to set this attached property value. Call SetLabeledBy, passing the element being labeled as the first parameter and a reference to the label as the second parameter. If you are declaring control composition in a template, and you are the control author, you could make this call part of your OnApplyTemplate handling. Otherwise, you might need to add a handler at the page level for LayoutUpdated in order to apply the various LabeledBy values to the XAML-generated UI.

XAML Attribute Usage

<object AutomationProperties.LabeledBy="{Binding ElementName=labelElement}"/>

See Also

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.