在ContentDialog的按钮上设置AutomationIdProperty

时间:2018-11-09 00:08:59

标签: uwp automated-tests win-universal-app accessibility windows-10-universal

为了测试自动化以及可访问性,我试图在以编程方式创建的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? 如果没有,有人可以告诉我如何使以上代码正常工作吗?

0 个答案:

没有答案