ens*_*s91 2 c# xaml combobox ui-automation
我对 XAML 或绑定不太熟悉,但我一直在每个 GUI 元素上设置 AutomationID。不幸的是,我找不到在ComboBox.
以下是在 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}}" />
Run Code Online (Sandbox Code Playgroud)
在一个单独的类中,这是创建组合框中项目的地方。
public enum MoveType
{
[StringValue("INBOUND")] Inbound,
[StringValue("OUTBOUND")] Outbound
}
Run Code Online (Sandbox Code Playgroud)
我无法真正提供更多代码,但我可以尝试回答任何问题。
小智 5
我认为您需要定义一个 ItemTemplate ,然后您可以将 Automationid 放入每个元素。例如
<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>
Run Code Online (Sandbox Code Playgroud)