Hello, I have my own Element called SmallModal
public class SmallModal : VisualElement
{
public new class UxmlFactory : UxmlFactory<SmallModal> { }
public SmallModal()
{
Init();
}
private void Init()
{
var asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/_Project/Components/Core/Modals/SmallModal/SmallModal.uxml");
asset.CloneTree(this);
}
}
next I need to use it as a container for content, I have applied content-container=“true”, but it doesnt work
CloseButton is OK, it is in the SmallModal.uxml, but If I use it as an own component with content -
result:

What Am I doing wrong please?
Any help please? The content-container attribute is not applied. The inserted elements are displaying on bad parent
The “modalPanelContainer” is indeed the content-container of the SmallModal.uxml template.
However, I think the issue is that nothing overrides the contentContainer of your SmallModal custom control instance.
On C# side, at Init, try to set the contentContainer property to the cloned VisualElement added to your SmallModal custom control. I am curious to know if the contentContainer properties will chain properly, because :
- the contentContainer of the SmallModal custom constrol instance would be the SmallModal.uxml template instance
- the contentContainer of the SmallModal.uxml template instance is “modalPanelContainer”
If it doesn’t work out of the box, you might need to set the contentContainer explicitly to your “modalPanelContainer” VisualElement, that you can query with .Q(“modalPanelContainer”).