为了测试自动化以及可访问性,我试图在以编程方式创建的ContentDialog的按钮上设置Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty。
这是我尝试过的:
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();
我的问题是: 是否有更好,更简便的方法来设置AutomationIdProperty? 如果没有,有人可以告诉我如何使以上代码正常工作吗?