barker1889
barker1889

Reputation: 37

DoubleAnimation - On start event?

I have a storyboard defined:

    <Grid.Resources>
        <Storyboard x:Key="MasterAnim" x:Name="MasterAnim" Duration="0:0:10" >
            <DoubleAnimation x:Name="ANIMATABLE_WidthExp"
                             Storyboard.TargetName="ANIMELEMENT_SboardRect1" 
                             Storyboard.TargetProperty="Width"
                             From="100" 
                             To="800" 
                             Duration="0:0:5" />

            <DoubleAnimation x:Name="ANIMATABLE_HeightExp"
                             Storyboard.TargetName="ANIMELEMENT_SboardRect1" 
                             Storyboard.TargetProperty="Height"
                             From="100" 
                             To="800" 
                             BeginTime="0:0:5"
                             Duration="0:0:5" />
        </Storyboard>

    </Grid.Resources>

Is there any way of capturing when each of the double animations are about to start? I need to call a method on the element that it's targeting before the animation starts but im not sure what the best way to go about it is.

Upvotes: 0

Views: 1910

Answers (1)

Phil
Phil

Reputation: 42991

There's no Started event, but you can handle the CurrentTimeInvalidated, CurrentStateInvalidated and Completed events on the DoubleAnimation. CurrentStateInvalidated is probably all you need.

private void DoubleAnimationCurrentTimeInvalidated(object sender, EventArgs e)
{
    var clock = (AnimationClock) sender;

    Debug.WriteLine(string.Format("CurrentTime: state={0}, progress={1}, time={2}", clock.CurrentState, clock.CurrentProgress, clock.CurrentTime));
}

private void DoubleAnimationCurrentStateInvalidated(object sender, EventArgs e)
{
    var clock = (AnimationClock)sender;

    Debug.WriteLine(string.Format("CurrentState: state={0}", clock.CurrentState));
}

private void DoubleAnimationCompleted(object sender, EventArgs e)
{
    var clock = (AnimationClock) sender;

    Debug.WriteLine(string.Format("Completed: state={0}", clock.CurrentState));
}

Ignoring the current time we get

  CurrentState: state=Active

  CurrentState: state=Filling

  Completed: state=Filling

when the animation runs.

Upvotes: 2

Related Questions