Reputation: 4520
I have a WPF application that has a few legacy panels that were written mostly with code behind. I need to set the AutomationProperties.AutomationId for the controls on the panel. For example, this Checkbox
CheckBox myCheckbox = new CheckBox();
How can I set AutomationProperties.AutomationId?
Upvotes: 5
Views: 5757
Reputation: 11
Try this:
AutomationProperties.SetAutomationId(myCheckbox, "YourDesiredname");
Ofcourse you need to include the namespace.
using System.Windows.Automation;
Upvotes: 1
Reputation: 56
You have to add the Name property "myCheckbox" to the xaml checkbox definition to use the following LOC:
myCheckbox.SetValue(AutomationProperties.AutomationIdProperty, "checkBoxAutoID");
You can alternatively define in xaml:
<CheckBox x:Name="myCheckbox"
... AutomationProperties.AutomationId="mycheckBoxAutoID" ...
</CheckBox >
Upvotes: 1
Reputation: 17402
myCheckbox.SetValue(AutomationProperties.AutomationIdProperty, "checkBoxAutoID");
Upvotes: 13