Tilak
Tilak

Reputation: 30738

Strange behavior of EventTrigger (WPF)

Considering following example (taken from MSDN sample)

<Style TargetType="Rectangle">
  <Style.Triggers>
    <EventTrigger RoutedEvent="MouseEnter">
        <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation To="300" Duration="0:0:1.5" 
                AccelerationRatio="0.10" DecelerationRatio="0.25" 
                Storyboard.TargetProperty="(Canvas.Width)" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
    <EventTrigger RoutedEvent="MouseLeave">
        <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation Duration="0:0:1.5" 
                AccelerationRatio="0.10" DecelerationRatio="0.25" 
                Storyboard.TargetProperty="(Canvas.Width)" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
  </Style.Triggers>
</Style>

There are 2 animiations, one for MouseEnter event, and another one for Mouse leave event.

Note that In the animation of Mouse Leave event, only Duration is specified. No From/To.By is specified. The remark section of DoubleAnimation specified either of From/To/By must be specified. My question is how this animation is working? Is it considering original value of rectangle as To value for the animation.

Upvotes: 0

Views: 254

Answers (1)

Kevin Nacios
Kevin Nacios

Reputation: 2853

its working by transitioning back to the default value. the table you referred to only specifies behavior when various combinations of from/to/by are used.

each storyboard is independent, so they wont keep track of what the other storyboard has done, so the first one transitions to the width defined, and the second will transition it back to the original value.

Upvotes: 1

Related Questions