[英]Add Automation ID to bound combo box items
I am not too familiar with XAML or binding, but I have been setting AutomationID's on each GUI element. 我对XAML或绑定不太熟悉,但是我一直在每个GUI元素上设置AutomationID。 Unfortunately I can't find a way to set an AutomationID on items in a
ComboBox
. 不幸的是,我找不到在
ComboBox
项目上设置AutomationID的方法。
Here is how the ComboBox is declared in XAML. 这是在XAML中声明ComboBox的方式。
<ComboBox AutomationProperties.AutomationId="DialogRODB_TypeComboBox"
Height="23"
Margin="80,64,27,0"
VerticalAlignment="Top"
SelectedValue="{Binding Message.Move.Type}"
ItemsSource="{Binding Source={StaticResource MoveType}}" />
And in a separate class, this is where the items in the combo box are created. 在单独的类中,这是在组合框中创建项目的地方。
public enum MoveType
{
[StringValue("INBOUND")] Inbound,
[StringValue("OUTBOUND")] Outbound
}
I can't really provide more code, but I can try to answer any questions. 我真的无法提供更多代码,但是我可以尝试回答任何问题。
I think you need to define an ItemTemplate and than you can put Automationid to each element. 我认为您需要定义一个ItemTemplate,然后可以将Automationid应用于每个元素。 For eg
例如
<DataTemplate x:Key="PersonDataTemplate" DataType="model:Person">
<TextBlock Text="{Binding Name}">
<AutomationProperties.AutomationId>
<MultiBinding StringFormat="AID_{0}-{1}">
<Binding Path="Name" />
<Binding Path="Id" />
</MultiBinding >
</AutomationProperties.AutomationId>
</TextBlock>
</DataTemplate>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.