0

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?

5
  • this: docs.avaloniaui.net/docs/reference/controls/… or maybe this: github.com/AvaloniaUI/Avalonia/discussions/… Commented Sep 24 at 9:01
  • What is not supported? Do you get an error (and it would be nice to see minimal reproducible example, like, what is 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? Commented Sep 24 at 9:35
  • No, it's normal, there is no need to define a standard property when creating attached one in avalonia it seems. Commented Sep 24 at 9:46
  • 1
    This question is similar to: Binding a dynamic automationID to every ListViewItem in a ListView. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Sep 25 at 11:01
  • My comment is a duplicate question boilerplate. Basically AutomationIdProperty is readonly. You need to use SetAutomationId (check their XAML using the setter tag). to set those. And even the Avalonia docs link shows its readonly. Commented Sep 25 at 11:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.