WPF implements the animation effect of moving left and right (shaking), while wpf shakes

Source: Internet
Author: User

WPF implements the animation effect of moving left and right (shaking), while wpf shakes

The examples in this article share with you the code for displaying the Left and Right mobile effects of WPF for your reference. The specific content is as follows:

DoubleAnimation and Storyboard are mainly used to move left and right controls or la S.

Layout code:

<Canvas>    <Grid Width="200" Height="100" Background="MediumAquamarine" Name="GroupboxArea" Canvas.Left="100" Canvas.Top="200"/>    <Button Content="Button" Height="25" Width="78" Click="Button_Click"/></Canvas>

The background code is:

Private void Button_Click (object sender, RoutedEventArgs e) {DoubleAnimation DAnimation = new DoubleAnimation (); DAnimation. from = 100; // start point: DAnimation. to = 280; // The end point is DAnimation. duration = new Duration (TimeSpan. fromSeconds (0.5); // time Storyboard. setTarget (DAnimation, GroupboxArea); Storyboard. setTargetProperty (DAnimation, new PropertyPath (Canvas. leftProperty); Storyboard story = new Storyboard (); story. completed + = new EventHandler (story_Completed); // what to do after completion // story. repeatBehavior = RepeatBehavior. forever; // infinite loop. You need to add the story yourself. children. add (DAnimation); story. begin ();} void story_Completed (object sender, EventArgs e) {DoubleAnimation DAnimation = new DoubleAnimation (); DAnimation. from = 280; // start point: DAnimation. to = 100; // The end point is DAnimation. duration = new Duration (TimeSpan. fromSeconds (0.5); // time Storyboard. setTarget (DAnimation, GroupboxArea); Storyboard. setTargetProperty (DAnimation, new PropertyPath (Canvas. leftProperty); Storyboard story = new Storyboard (); story. completed + = new EventHandler (storyCompleted); // what to do after completion // story. repeatBehavior = RepeatBehavior. forever; // infinite loop. You need to add the story yourself. children. add (DAnimation); story. begin ();} void storyCompleted (object sender, EventArgs e) {DoubleAnimation DAnimation = new DoubleAnimation (); DAnimation. from = 100; // start point: DAnimation. to = 200; // The end point is DAnimation. duration = new Duration (TimeSpan. fromSeconds (0.5); // time Storyboard. setTarget (DAnimation, GroupboxArea); Storyboard. setTargetProperty (DAnimation, new PropertyPath (Canvas. leftProperty); Storyboard story = new Storyboard (); // story. completed + = new EventHandler (storyCompleted); // what to do after completion // story. repeatBehavior = RepeatBehavior. forever; // infinite loop. You need to add the story yourself. children. add (DAnimation); story. begin ();}

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.