How to enable WPF control animation before removing from visual tree

I have a scenario in which I would like to animate a WPF control before it is removed from the visual / logical trees. Custom controls, and a management style, including animation, will be supplied by the designer (i.e. I don’t know the details of what they will be at the time of writing the control code). I would like to provide redirected events that allow the developer to start the animation right before the object is deleted (for example, the user drags the control with the mouse, and when you release the mouse button, the control may disappear slowly instead of being ubruptly removed from the visual / logical tree). Is this only possible with routed events? Is it possible to detect when the animation has completed without requiring the designer to set the quirky dependency property or at the end of the animation?to cause the removal of the control? Using the dependency property would create a memory leak if the developer was unable to set the property. Is there a better way?

+3
source share
1 answer

Each storyboard has a Completed event that fires during animation. You must handle this event and remove the control from this event. That way you can just start the animation when you release the mouse button.

+2
source

Source: https://habr.com/ru/post/1698762/


All Articles