Blue Theme Orange Theme Green Theme Red Theme
 
MindFusion's Components
Home | Forums | Videos | Photos | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » XAML » Your first Animation using XAML and Silverlight - Point Animation class: Part III

Your first Animation using XAML and Silverlight - Point Animation class: Part III

This article is third part of the series of articles about animation using XAML and Silverlight.

Author Rank:
Technologies: Database, Silverlight,Visual C# .NET
Total downloads :
Total page views :  2947
Rating :
 0/5
This article has been rated :  0 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
ArticleAd
Become a Sponsor




I the previous articles Your first animations using XAML and Silverlight - Color animation: Part I and Your first animations using XAML and Silverlight- Double animation: Part II, we discovered how to deal with ColorAnimation and DoubleAnimation classes. In this one we will show how to deal with PointAnimation class to perform a linear interpolation movement between two points of a given object. As a first step, we will perform this with xaml then we will do the same animation using the C# code.

If you have already developed Adobe Flash projects like me, you will observe that this kind of animation class helps to perform the same task as a given linear interpolation movement done with flash. 

Ok, let's consider an ellipse that moves from a point to another as mentioned within this bellow presentation:

Figure 1

To perform this, I propose this xaml and C# code:

XAML Code:

<Window x:Class="myWpfApplication.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Window1" Height="400" Width="400" Loaded="Window_Loaded">

    <!--I used canvas this once as container to host child element -->

        <Canvas>

            <!--Don't confuse with System.IO.Path class

            this one is System.Windows.Shapes.Path witch

            is responsible to draw curves-->

            <Path Fill="Beige" Margin="0,0,200,200">

                <Path.Data>

 

                    <!-- Describes an ellipse. -->

                    <EllipseGeometry x:Name="MyAnimatedEllipseGeometry"

            Center="200,110" RadiusX="150" RadiusY="100" />

                </Path.Data>

                <Path.Triggers>

                    <!--The Loaded event of the path class will

                    trigger the point aniamtion-->

                    <EventTrigger RoutedEvent="Path.Loaded">

                        <BeginStoryboard Name="MyBeginStoryboard">

                            <Storyboard>

 

                <!-- Animate the Center property so that the ellipse animates from

                one point on the screen to another. -->

                                <PointAnimation

                Storyboard.TargetProperty="Center"

                Storyboard.TargetName="MyAnimatedEllipseGeometry"

                Duration="0:0:8" From="200,110" To="200,290" RepeatBehavior="Forever" />

                            </Storyboard>

                        </BeginStoryboard>

                    </EventTrigger>

                </Path.Triggers>

            </Path>

        </Canvas>  

</Window>

In the xaml code editor copy and paste the above code instead of the existing code, then run the project and observe.

C# code:

To perform this task using C#, open a new WPF application and then add this code to the C# code editor, for instance, don't forget to include the both namespaces System.Windows.Media.Animation and System.Windows.Shapes if they aren't included yet.

//The shape container

        Canvas myCanvas;

        //The curve

        Path myPath;

        //The shape form

        EllipseGeometry myEllipseGeometry;

        //The PointAnimation instance

        PointAnimation oPointAnimation;

        private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            //Instantiate the canvas container

            myCanvas = new Canvas();

            //Instantiate the curve

            myPath = new Path();

            //The the fill color as beige

            myPath.Fill = Brushes.Beige;

            //Set the shape volume

            myPath.Margin = new Thickness(0, 0, 200, 200);

            /* instantiate the ellipse shape, you can make use of the ellipse

             * class directly instead of using ellipse geometry and path classes

             to draw an ellipse*/

            myEllipseGeometry = new EllipseGeometry(new Point(200, 110), 150, 100);

            //Set the path data to the given ellipse geometry

            myPath.Data = myEllipseGeometry;

            //Add the path to the canvas container

            myCanvas.Children.Add(myPath);

            //Finally, add the container to the form

            this.AddChild(myCanvas);

            myPath.Loaded+=new RoutedEventHandler(myPath_Loaded);

        }

        private void myPath_Loaded(object sender, RoutedEventArgs e)

        {

            oPointAnimation = new PointAnimation();

            oPointAnimation.From = new Point(200, 110);

            oPointAnimation.To = new Point(200, 290);

            oPointAnimation.RepeatBehavior = RepeatBehavior.Forever;

            oPointAnimation.Duration = TimeSpan.FromSeconds(8);

            myEllipseGeometry.BeginAnimation(EllipseGeometry.CenterProperty,oPointAnimation);

        }

Now run the project and you will remark the same behaviour as the first. You can combine animations, I mean double animation, color animation and point animation to build a complex one. 

Good Dotneting!!!


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Bechir Bejaoui
The author holds a master degree in NTIC specialized  in software developement delivered by the high school of communication SUPCOM, he also holds a bachelor degree in finance delivered by  the  economic sciences and  management  university of Tunis "FSEGT". He's a freelance developer since 2006. Actually woking on the WPF, .Net framewok 3.5, silverlight and the other .Net new features, in addition, he is painter and sculptor.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Boost the performance of your .NET applications
“ANTS Profiler took us straight to the specific areas of our code which were the cause of our performance issues." Terry Phillips, Sr. Developer, Harley-Davidson Dealer Systems. Download your free trial of ANTS Profiler.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
ArticleAd
Become a Sponsor
Latest Comments:
Subject Posted By Posted On

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved