C# 如何将AutomationId属性正确设置为ItemsControl?
我面临WPF中ui自动化的问题。我在测试中无法通过查询找到控件项C# 如何将AutomationId属性正确设置为ItemsControl?,c#,wpf,xaml,ui-automation,C#,Wpf,Xaml,Ui Automation,我面临WPF中ui自动化的问题。我在测试中无法通过查询找到控件项 rootElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "AID_Positions"))) 它总是返回null。在接口检查器中,我看到属性已满,并且具有正确的值“AID_Positions” 我的xaml <ItemsControl G
rootElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "AID_Positions")))
它总是返回null。在接口检查器中,我看到属性已满,并且具有正确的值“AID_Positions”
我的xaml
<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。
我做错了什么?尝试使用检查WPF UI,看看工具是否可以导航到ItemsControl。您的ItemsControl可能不是根元素的子树。此工具将帮助您验证这一点。也可能有一些中间自定义wpf元素不支持UIA,并且不允许查找其子元素