Grouping buttons for eventCallback logic

I found this older thread: Is there a way to register events for all elements of a class? which describes the call back itself.

But I have a couple of questions related to it:
What sort of object is “m_ButtonArrayContainer” in the example? It doesn’t appear to be a normal list or array as the method for call back appears specific to UI toolkit. For example I’m trying:

List<VisualElement> textureButtonList;
textureButtonList = ui.Query(className: "textureButton").ToList();

This creates the list and grabs the elements correctly, Just can’t seem to bind any callback off this list.

And looking a bit into the future here, I’d likely need to have some piece of data from each button that fires the event. In HTML you could just insert data attributes into the HTML tags like

"<div data-thing="42">

and just reference the data attribute for callbacks. Is there a similar function for UI toolkit?

Wouldn’t you just enumerate the list and register an event to each of them?

I was going for something more like the delegated event handling you see in JS or Jquery since UI-Toolkit seems to be drawing from those concepts. In essence you just bind a call back to the parent container and say whenever a button in this container is clicked fire the event.

Pull the data you need from the specific object (button) that fired the event and then run that data through your method. It’s a lot cleaner and allows for more dynamic stuff (like adding or removing buttons)

I mean to answer this question specifically:

It’s just registered to the common parent visual element of the buttons. That’s it. Though it should probably be registered with trickle down.

Ergo:

container.RegisterCallback<ClickEvent>(Callback, TrickleDown.TrickleDown);;