AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.26k stars 2.19k forks source link

Expose control when creating custom transitions #7425

Open wihrl opened 2 years ago

wihrl commented 2 years ago

When trying to create a custom transition by overriding Transition<T>, one has to override the DoTransition method. This method does not get a reference to the control currently being handled, but I've noticed that the parent method Apply does actually have it. It would be very useful to pass this Animatable reference to the DoTransition method for changing the behaviour of a transition on a per-control basis.

An alternative would be to instead inherit the ITransition interface. There I've ran into another problem: the class TransitionInstance is internal, so I cannot create an instance of it in my project, rendering the ITransition interface quite useless. (At least without having to create my own timer)

Please either pass the Animatable reference to the DoTransntion method or make the TransitionInstance class public.

jmacato commented 2 years ago

May i ask what's your usecase? I designed some of the animation APIs and i might be able to see what we need to change there

wihrl commented 2 years ago

I'm trying to create an animation for adding and removing items. Basically when something is added play an animation and when something is removed first play an animation and then remove.

The best way of doing this i've found so far is to not add and remove stuff but instread set the IsVisible property. I've created a transition for this property that effectively "delays" the setter while letting the animation play out first by adding a certain class to the control that is transitioning.

This works well, but I need to create the transition instances from code and pass a reference to the control so that the transition can actually change the class of the control.

If the DoTransition method had the reference passed into it, this wouldn't be necessary and I could simply add the transition in XAML.