Hello,
I have the following XAML:
<StackPanel>
<Label Target="{Binding ElementName=txtSearch}" Content="_Search:" />
<TextBox x:Name="txtSearch" />
</StackPanel>
I have an extension method that accepts a UIElement parameter like so:
static public class MyExtensionMethods
{
static public string GetLabelText(this UIElement element)
{
}
}
All I want to do inside of the GetLabelText method is to determine the Content of the Label (if there is one) that is targeting the passed UIElement, and return the text. For example, the following code would return "_Search:":
string labelText = txtSearch.GetLabelText();
I have heard that you can do this using AutomationPeers, but I have not had much exposure to the UIAutomation features as of yet and can't seem to get anything back but null values from calls to GetLabeledBy on any of the Automation examples I've found. Any answer that works would be most helpful, but I'd prefer to not have to do anything extra in my XAML except what you already see here.
Any ideas?