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.