How to access non-standard attributes from UXML?

I want to augment VisualElements with custom data.
I expected that I could use some additional attributes in UXML.

However, I do not see an API to query non-standard attributes from UXML.
Is there no map with all attributes from UXML?
What I am looking for is the equivalent of Element.attributes

Motivation
I implemented some custom VisualElement navigation. Thereby, I want to be able to specify navigation targets manually via custom UXML attributes.
I use regular VisualElements (Button, TextField) and do not want to implement my own just for some additional attributes.

2 Likes

Hello,

I’m afraid what you are asking for isn’t possible without creating custom elements.

Wow, that’s a surprise! Would be easy to use and flexible enough for many use cases.

There seems to be one attribute userData but can this be set from UXML?
However, this is not a great solution because it is likely to conflict with other usages of the same field.

My idea was to use custom attributes like navigation-target-left, navigation-target-right etc.
Guess I have to think again…

I still think custom attributes in UXML would make the framework much more flexible.

It would allow us to associate elements with custom data.

For example, HTML has data attributes because it was desinged with extensibility in mind ( Using data attributes - Learn web development | MDN) .

The same could be done with UXML.
I think exposing a map of attributes would be a low hanging fruit, easy to implement but with great benefit for the user.

2 Likes

+1