🤔

UI Toolkit: Resolved style#

UI Toolkit resolves styles asynchronously.
resolvedStyle, layout, contentRect, paddingRect, and others, will return invalid values before it has been initialised.

Resolution#

These members are initialised after an element is created in the hierarchy.
You can use GeometryChangedEvent or AttachToPanelEvent to read from these values when they are valid.

_visualElement.RegisterCallback<GeometryChangedEvent>(
    _ =>
    {
        // _visualElement.resolvedStyle will contain initialised values.
    }
);