Style inheritance from code

On a Parent > Childs hierarchy, where childs are created and appended dynamically from code I would like to be able to toggle visibility on either individual childs or the whole hierarchy (while I still need to process their geometry, thus not being unable to use display.none).

I noticed that if I enable visibility on the child and then turn it off on its parents, the childs stays visible, I suppose that when I set visibility from code on the child it turn into a override.

Is there a way I can reestablish style inheritance in that case ?

Style inheritance also seems to stop whenever there is a TemplateContainers in the visualtree, is there any way to get it to go through ?

TemplateContainers are like any VisualElements and don’t have special behaviour regarding styles. They can however get inline styles from the uxml itself. The UIToolkit debugger can help figuring out where the style values come from.

If inlining the visibility value doesn’t work for you, you can maybe do it by sending your elements far away instead of hiding them:

.hidden-element{
translate : -5000px, -5000px;
}