none
how to get the objects which have been animated by a storyboard after it has finished? RRS feed

  • Question

  • Is there any possibility to get the objects that were animated when an animation has finished? So when a storyboard has finished [which can be cought with an eventhandler on the CurrentStateInvalidated Event] i want to know, on which objects animations have been applied.

    For example when i have a dynamically created grid with rectangles and want wo fade one out and then remove it from the grid, i don't know how to get which one i should remove after the animation has finished in the CurrentStateInvalidated handler.
    Is there an elegant way to get the animated objects or do i have to create a FIFO in which i put the name of the rectangle when i start the animation, then get it from there after the animation and remove the rectangle with the coresponding name from the grid?
    Sunday, January 22, 2006 11:40 AM

Answers

  • Given a Storyboard resource used to fade out a FrameworkElement:

    <Storyboard x:Key="FaderStoryboard"
                        TargetName="MyElement"
                        CurrentStateInvalidated="OnFaderDone">
           <DoubleAnimation Storyboard.TargetProperty="(Opacity)"
                       To="0"
                        RepeatBehavior="1x"
                        AutoReverse="False"
                        FillBehavior="Stop"
                        To="0"
                         BeginTime="0:0:0"
                         Duration="0:0:5" />
     </Storyboard>

    In the OnFaderDone event handler, get the clock's Timeline, then get the Storyboard.TargetNameProperty and use that to find the element the storyboard acts on.

    e.g.
    void OnFaderDone(object sender, EventArgs e)
    {
       Clock theclock = sender as Clock;
       string sendername = (string) clock.Timeline.GetValue(Storyboard.TargetNameProperty);
       FrameworkElement f =  this.FindName(sendername) as FrameworkElement;
    }
    Thursday, January 26, 2006 4:07 PM

All replies

  • does anyone understand what i want?
    Thursday, January 26, 2006 8:38 AM
  • Given a Storyboard resource used to fade out a FrameworkElement:

    <Storyboard x:Key="FaderStoryboard"
                        TargetName="MyElement"
                        CurrentStateInvalidated="OnFaderDone">
           <DoubleAnimation Storyboard.TargetProperty="(Opacity)"
                       To="0"
                        RepeatBehavior="1x"
                        AutoReverse="False"
                        FillBehavior="Stop"
                        To="0"
                         BeginTime="0:0:0"
                         Duration="0:0:5" />
     </Storyboard>

    In the OnFaderDone event handler, get the clock's Timeline, then get the Storyboard.TargetNameProperty and use that to find the element the storyboard acts on.

    e.g.
    void OnFaderDone(object sender, EventArgs e)
    {
       Clock theclock = sender as Clock;
       string sendername = (string) clock.Timeline.GetValue(Storyboard.TargetNameProperty);
       FrameworkElement f =  this.FindName(sendername) as FrameworkElement;
    }
    Thursday, January 26, 2006 4:07 PM
  • thank you very much! will try it and see if it fits my needs!
    Friday, January 27, 2006 11:03 AM