I have a listbox defined as follows:
<ListBox Name="MyListBox"
AutomationProperties.AutomationId="MyWindow_MyListBox"
ItemsSource="{Binding MyItems}"
SelectedItem="{Binding MySelectedItem}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel Classes="list-item"
Width="{Binding $parent[ItemsControl].Presenter.Panel.Bounds.Width}"
AutomationProperties.AutomationId="{Binding MyItemId, Mode=OneTime}">
...
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
This however means that the item's Automation ID is not actually available on the actual list item that I want to click (because it is defined on a control inside the template) - instead, I can only retrieve the list item by index.
I already tried to define the automation ID on the DataTemplate element, but that seems not to be supported.
Is it somehow possible to bind to the list item's automation ID property?
MyItemId)? The AutomationIdProperty is an attached property, it should support binding. Though I couldn't find a normal property in docs, only methods and fields, which is weird - is this your problem?