【问题标题】:How to set AutomationId property to ItemsControl correctly?如何正确将 AutomationId 属性设置为 ItemsControl?
【发布时间】:2019-01-23 00:00:32
【问题描述】:

我在 WPF 中遇到了 ui-automation 的问题。我在测试中无法通过查询找到项目控制

rootElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "AID_Positions")))

它总是返回null。在界面检查器中,我看到该属性已满且具有正确的值“AID_Positions”。

我的 xml

       <ItemsControl
            Grid.Row="1"
            Grid.Column="1"
            VirtualizingStackPanel.IsVirtualizing="True"
            ScrollViewer.CanContentScroll="True">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    // data
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.Template>
                <ControlTemplate>
                    <Border
                        SnapsToDevicePixels="True">
                        <ScrollViewer
                           AutomationProperties.AutomationId="AID_Positions">
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ItemsControl.Template>
        </ItemsControl>

我将“AutomationProperties.AutomationId”属性设置为 ScrollViewer。 我做错了什么?

【问题讨论】:

    标签: c# wpf xaml ui-automation


    【解决方案1】:

    尝试使用UIA verify tool 检查您的 WPF UI 并查看该工具是否可以导航到您的 ItemsControl。您的 ItemsControl 可能不是您的 rootElement 的子树。该工具应该可以帮助您验证这一点。也可能存在一些不支持 UIA 并且不允许查找其后代元素的中间自定义 wpf 元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多