Why does the following animation flicker and act goofy on MouseLeave? If it can be repro-ed, I’ll post a screencast.
<Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Canvas> <Path Fill='Blue' Margin='15,15,15,15'> <Path.Data> <!-- Describes an ellipse. --> <EllipseGeometry x:Name='MyAnimatedEllipseGeometry' Center='200,100' RadiusX='15' RadiusY='15' /> </Path.Data> <Path.Triggers> <EventTrigger RoutedEvent='UIElement.MouseEnter'> <BeginStoryboard> <Storyboard Duration='0:0:.5'> <DoubleAnimation Storyboard.TargetName='MyAnimatedEllipseGeometry' Storyboard.TargetProperty='RadiusX' From='15' To='100' /> <DoubleAnimation Storyboard.TargetName='MyAnimatedEllipseGeometry' Storyboard.TargetProperty='RadiusY' From='15' To='100' /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent='UIElement.MouseLeave'> <BeginStoryboard> <Storyboard Duration='0:0:.5'> <DoubleAnimation Storyboard.TargetName='MyAnimatedEllipseGeometry' Storyboard.TargetProperty='RadiusX' From='100' To='15' /> <DoubleAnimation Storyboard.TargetName='MyAnimatedEllipseGeometry' Storyboard.TargetProperty='RadiusY' From='100' To='15' /> </Storyboard> </BeginStoryboard> </EventTrigger> </Path.Triggers> </Path> </Canvas> </Page>
The reason is that you specify a
Fromon yourDoubleAnimations.If the radius is anything less than 100 when
MouseLeavehappens, theFromproperty will make it jump up to 100 and likely cause aMouseEnter. Then, you have two competing animations and the mouse events go crazy as the ellipse radius flickers underneath the cursor.The solution is to just omit the
Fromproperties, this will cause the animation to start from wherever the current radius is:On an unrelated note, when you set
Storyboard.Duration, it won’t speed up your child animations, it will just end theStoryboardprematurely. You really want to setDurationon your childDoubleAnimations – I’ve modified the XAML above to do this.