XAML Bouncing Ball Storyboard

Hmm how to explain ?  

An Ellipse is moving across the screen and when it 'hits' the edge of the screen, it changes direction (angle of incidence = angle of reflection etc)

How can I mimic this behaviour as part of an XAML Storyboard ?

(is there no Silverlight Topic?)
WatersideAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Try this.

   private void rectangle1_MouseDown(object sender, MouseButtonEventArgs e) 
        { 
            ThicknessAnimation bounceAnimation = new ThicknessAnimation(); 
            BounceEase BounceOrientation = new BounceEase(); 
            BounceOrientation.Bounces = 4; 
            BounceOrientation.Bounciness = 2; 
            bounceAnimation.To = new Thickness(143,200,0,0); 
            bounceAnimation.From = new Thickness(143,0,0,0); 
            bounceAnimation.EasingFunction = BounceOrientation; 
            rectangle1.BeginAnimation(MarginProperty, bounceAnimation); 
        }

Open in new window


<Window x:Class="WpfApplication1.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
        <Rectangle Name="myRectangle" Width="200" Height="30" Fill="Blue"> 
            <Rectangle.Triggers> 
                <EventTrigger RoutedEvent="Rectangle.MouseDown"> 
                    <BeginStoryboard> 
                        <Storyboard> 
                            <Storyboard x:Name="myStoryboard"> 
                                <DoubleAnimation From="30" To="200" Duration="00:00:3"  
                     Storyboard.TargetName="myRectangle"  
                     Storyboard.TargetProperty="Height"> 
                                    <DoubleAnimation.EasingFunction> 
                                        <BounceEase Bounces="2" EasingMode="EaseOut"  
                             Bounciness="3" /> 
                                    </DoubleAnimation.EasingFunction> 
                                </DoubleAnimation> 
                            </Storyboard> 
 
                        </Storyboard> 
                    </BeginStoryboard> 
                </EventTrigger> 
            </Rectangle.Triggers> 
 
        </Rectangle> 
    </Grid> 
</Window>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WatersideAuthor Commented:
Hi. Sorry.. I haven't neglected this.. Just side tracked with other jobs.. I'll test it when I have a minute free tnx
0
Randy DownsOWNERCommented:
This should have worked

Great sample I'm using it for a project, it is amazing and very easy to implement
0
Randy DownsOWNERCommented:
This should have worked

Great sample I'm using it for a project, it is amazing and very easy to implement
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.