AutomationProperties.LabeledBy Attached Property
May 11, 2014
Gets or sets the element that contains the text label for the element.
Assembly: System.Windows (in System.Windows.dll)
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 for Windows Phone 8.
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.
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 values to the XAML-generated UI.