Bouncing Ball : Ball Animation « Windows Presentation Foundation « C# / CSharp Tutorial






<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="clr-namespace:System;assembly=mscorlib">


    <Ellipse Name="elips" Width="20" Height="20" Fill="Red" Canvas.Left="96">

        <Ellipse.Triggers>
            <EventTrigger RoutedEvent="Ellipse.Loaded">
                <BeginStoryboard>
                    <Storyboard TargetName="elips" 
                                TargetProperty="(Canvas.Top)"
                                RepeatBehavior="Forever">
                        <DoubleAnimationUsingKeyFrames>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="96" />
                            <SplineDoubleKeyFrame KeyTime="0:0:1" Value="480" 
                                                  KeySpline="0.25 0, 0.6 0.2" />
                            <SplineDoubleKeyFrame KeyTime="0:0:2" Value="96"
                                                  KeySpline="0.75 1, 0.4 0.8" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Ellipse.Triggers>
    </Ellipse>
</Canvas>
WPF Bouncing Ball








24.113.Ball Animation
24.113.1.Bouncing BallBouncing Ball
24.113.2.Bouncing Ball with ParallelTimelineBouncing Ball with ParallelTimeline
24.113.3.Bouncing Ball with DoubleAnimationBouncing Ball with DoubleAnimation
24.113.4.Ball moves in a constant speedBall moves in a constant speed
24.113.5.Rolling Ball AnimationRolling Ball Animation
24.113.6.Animate Ball HeightAnimate Ball Height