南宁市制作网站的公司,产品展示型网站有哪些,没有域名 怎么做网站链接,罗湖商城网站设计费用先#xff0c;我们需要在XAML中定义一个Path#xff0c;这个Path将定义动画的路线。然后#xff0c;我们将使用DoubleAnimationUsingPath来沿着这个路径移动一个元素#xff08;比如一个矩形#xff09;。
Window x:ClassWpfApp.MainWindow xmlns…先我们需要在XAML中定义一个Path这个Path将定义动画的路线。然后我们将使用DoubleAnimationUsingPath来沿着这个路径移动一个元素比如一个矩形。
Window x:ClassWpfApp.MainWindow xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitlePath Animation Example Height350 Width525 Grid Canvas NamemyCanvas !-- 定义路径 -- Path x:NamemyPath StrokeBlack StrokeThickness2 DataM 10,100 C 100,10 200,200 300,100/!-- 定义一个矩形我们将对其进行动画处理 -- Rectangle NamemyRectangle Width20 Height20 FillRed Canvas.Left10 Canvas.Top100 Rectangle.RenderTransform TranslateTransform x:NamerectTransform X0 Y0/ /Rectangle.RenderTransform !-- 定义动画 -- Rectangle.Triggers EventTrigger RoutedEventLoaded BeginStoryboard Storyboard !-- 路径动画 -- DoubleAnimationUsingPath Storyboard.TargetNamerectTransform Storyboard.TargetPropertyY PathGeometry{Binding Data, ElementNamemyPath} Duration0:0:5 RepeatBehaviorForever AutoReverseTrue/ /Storyboard /BeginStoryboard /EventTrigger /Rectangle.Triggers /Rectangle !-- 注意为了简化示例我没有直接在XAML中给Path命名但在实际使用中你可能需要这样做来绑定 -- !-- Path x:NamemyPath StrokeBlack StrokeThickness2 DataM 10,100 C 100,10 200,200 300,100/ -- /Canvas /Grid
/Window 在代码后台MainWindow.xaml.cs中设置动画并绑定到Path的Data。 public MainWindow()
{ InitializeComponent(); DoubleAnimationUsingPath pathAnimation new DoubleAnimationUsingPath { Duration TimeSpan.FromSeconds(5), RepeatBehavior RepeatBehavior.Forever, AutoReverse true, PathGeometry myPath.Data.GetFlattenedPathGeometry() }; Storyboard.SetTargetName(pathAnimation, rectTransform); Storyboard.SetTargetProperty(pathAnimation, new PropertyPath(Y));