views:

1521

answers:

2

I have a scenario where I would like to animate a WPF control right before it is removed from the visual/logical trees. The control is custom, and the control style, including animations would be supplied by a 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 routed events that allow the designer to trigger an animation right before the object is removed (e.g. the user is dragging the control with the mouse, and when the mouse button is released the control might fade away slowly instead of ubruptly being removed from the visual/logical tree). Is this possible just using routed events? Is it possible to detect when the animation has completed without requiring the designer to set a quirky dependency property or at the end of the animation to trigger the removal of the control? Using a dependency property would create a memory leak if the designer failed to set the property. Is there a better way?

+1  A: 

Every storyboard has a Completed event that is called when the animation is done. You should handle that event and delete the control from that event. That way you can just start the animation when the mouse button is released.

Sorskoot
Without knowing the storyboard by name, how would I handle the Completed event? (I'm assuming the control is templated by a designer, and may or may not include any animations). Is handling the completed event the only way?
A: 

How to show animation while an operation takes place... Kindly forgive me if this is not a right place to post my question..

Aizaz
Use the button "Ask Question" in the top right corner of the web page to ask your own question.
Martin Liversage