For the sake of Testing automation and also Accessibility, I'm trying to set the Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty on the buttons of a ContentDialog which is created programmatically.
Here is what I have tried:
ContentDialog dialog = new ContentDialog()
{
Content = "This is my Content",
Title = "This is my Title",
PrimaryButtonText = "Primary Button",
SecondaryButtonText = "Secondary Button",
};
// Don't know how to make this work
Button primaryButton = closeDialog.FindName("PrimaryButton") as Button;
if (primaryButton != null)
{
primaryButton.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, "PrimaryCloseButton");
}
await dialog.ShowAsync();
My questions are: If there is a better, easier way to set the AutomationIdProperty? If not, can someone tell me how to make the above code work?