将自动化ID添加到绑定的组合框项目 [英] Add Automation ID to bound combo box items

查看:62
本文介绍了将自动化ID添加到绑定的组合框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太熟悉XAML或绑定,但是我一直在每个GUI元素上设置AutomationID。不幸的是,我找不到在 ComboBox 中的项目上设置AutomationID的方法。

I am not too familiar with XAML or binding, but I have been setting AutomationID's on each GUI element. Unfortunately I can't find a way to set an AutomationID on items in a ComboBox.

这是在XAML中声明ComboBox的方式。

Here is how the ComboBox is declared in XAML.

<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.

推荐答案

我认为您需要定义一个ItemTemplate,然后可以将Automationid应用于每个元素。
例如,

I think you need to define an ItemTemplate and than you can put Automationid to each element. For e.g.

<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>

这篇关于将自动化ID添加到绑定的组合框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆