XAML Code:
1<window x:class="path Animation. MainWindow"2xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"4title="MainWindow"height=" -"Width="525">5<Window.Resources>6<!--path Resources--7<pathgeometry x:key="Path">8<pathfigure isclosed="True">9<arcsegment point="200,200"Size="30,10"sweepdirection="Clockwise"></ArcSegment>Ten<arcsegment point="300,200"Size="5,5"></ArcSegment> One</PathFigure> A</PathGeometry> -</Window.Resources> -<!---event trigger, the form loads when the animation starts, cycle 6 seconds, infinite loop-- the<Window.Triggers> -<eventtrigger routedevent="window.loaded"> -<BeginStoryboard> -<Storyboard> +<doubleanimationusingpath storyboard.targetname="Image"storyboard.targetproperty="(Canvas.Left)" -pathgeometry="{StaticResource path}"duration="0:0:6"Repeatbehavior="Forever"Source="X"></DoubleAnimationUsingPath> +<doubleanimationusingpath storyboard.targetname="Image"storyboard.targetproperty="(canvas.top)" Apathgeometry="{StaticResource path}"duration="0:0:6"Repeatbehavior="Forever"Source="Y"></DoubleAnimationUsingPath> at</Storyboard> -</BeginStoryboard> -</EventTrigger> -</Window.Triggers> -<Canvas> -<!--display path-- in<path margin=" -"Stroke="#ddd"Data="{StaticResource path}"></Path> -<!--animated Elements-- to<image name="Image"Source="123.png"Width=" -"height=" -"/> +</Canvas> -</Window>
View Code
. CS Code:
1 usingSystem.Windows;2 3 namespacePath Animation4 {5 /// <summary>6 ///the interactive logic of MainWindow.xaml7 /// </summary>8 Public Partial classMainwindow:window9 {Ten PublicMainWindow () One { A InitializeComponent (); - } - } the}
View Code
Path animation for WPF animation (3)