【发布时间】: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