Nesting UXML

Currently nesting is looks like very immature

  • UXML don’t have root element class
  • Adding nested uxml will add it not where I put it but inside additional container. Why?

Is there any plans to make it more like in XAML or any other UI framework where UI Control (UXML) has root element with any custom type that has any number of sub elements (or no)?

Hello,

Making a custom element as the root of a UXML is something we have explored but we believe there are more important features to implement first in the UI Toolkit workflow. For example, we want to improve the way you expose custom elements to C# to make it less verbose, less error prone and open the door to extending the inspector of the UI Builder.

That being said yes I think this would be a great feature to add.

The main reason is that you can have multiple elements at the root of the UXML document and we need a parent to represent the layout.

In C# it is possible to skip the extra element with the VisualTreeAsset.CloneTree(VisualElement) method (you provide the parent) but when nesting directly in UXML this is not possible (and I think would cause some ambiguity if we added this option).

Instead what we have mind is to allow defining styles for the root element of the UXML object, which would combine very well with having a custom element as the root as well.

1 Like