Appear animation?

It is possible for a VisualElement to transition from one IStyle state to another using transition properties. However, I have not been able to figure an obvious way to make an element animate its initial appearance on-screen, for example to fade-in when first displayed or animate its position coming up from the bottom.

Is there a way to accomplish this?

You can do

myElement.RegisterCallback<AttachToPanelEvent>(e =>
{
    myElement.AddToClassList("class-with-appear-transition");
});

If that doesn’t work, you can use the GeometryChangedEvent instead. Note that this event can be called for a variety of other reasons.

This still has the issue where you need to set up the element in it’s hidden state in the UI Builder, so when it loads it can then immediately be shown. Which is obviously non-ideal.

The only other solution I can think of is to, in code:

  • set transition time to 0
  • apply hidden styling
  • set transition time back to whatever it was before
  • apply visible styling

Which seems like a hack…