none
[UWP]How to Remove a storyboard once it has completed? RRS feed

  • Question

  • I found an old post "How to call a method after a Storyboard finished?" I didn't get far with that. It was a 2011 post. 

    So, in C# code, I have built several story boards, and more to write. Once they are run, I want to get rid of them to clear the resources.  I'll call the storyboard create when the next one is needed. So, say you shoot 4 birds. Each has a storyboard, to fall. There are a heck of a lot of birds going to die :-) .

    So, I was thinking of something that would go through a controls children, and remove those named with DeadBird in the name. I tired assigning a value name to it, but that didn't work.

    If I remove the object being animated, does that do it? If that works, and there is no better way, I can live with that. At least it will get cleaned up, if not as quickly as I would like.





    Sunday, September 8, 2019 12:08 AM

All replies

  • Hi,

    There is a completed event for the storyboard object. You can handle the Completed event if you want other logic to run after the animation has finished applying values. Then you could remove these dead birds from the layout in this event when the dead animation(maybe other animations :) ) finished.

    Like this:

          <Storyboard Completed="Storyboard_Completed">
                <DoubleAnimation>
                    ....
                </DoubleAnimation>
            </Storyboard>
    
    In code behind.
      private void Storyboard_Completed(object sender, object e)
            {
    
            }

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 9, 2019 2:53 AM
    Moderator