<Page x:Class="路径动画.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="路径动画">
<DockPanel Margin="20">
<StackPanel DockPanel.Dock="Left">
<Canvas HorizontalAlignment="Center" Width="340" Height="240">
<Path VerticalAlignment="Top" Margin="15,15,15,15" Data="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"
Stroke="LightBlue" StrokeThickness="2" Stretch="None"/>
<Path Fill="Red" Margin="0,0,15,15">
<Path.Data>
<RectangleGeometry x:Name="MyAnimatedRectGeometry" Rect="0,0,30 30"/>
</Path.Data>
<Path.RenderTransform>
<MatrixTransform x:Name="myMatrixTransform">
<MatrixTransform.Matrix>
<Matrix OffsetX="10" OffsetY="100"/>
</MatrixTransform.Matrix>
</MatrixTransform>
</Path.RenderTransform>
</Path>
</Canvas>
<WrapPanel HorizontalAlignment="Center">
<Button Width="120" Margin="10">
启动动画
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<MatrixAnimationUsingPath Storyboard.TargetName="myMatrixTransform"
Storyboard.TargetProperty="Matrix" Duration="0:0:5"
RepeatBehavior="Forever" AutoReverse="True">
<MatrixAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"/>
</MatrixAnimationUsingPath.PathGeometry>
</MatrixAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<Button Width="120" Margin="10">
启动动画(旋转)
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<MatrixAnimationUsingPath Storyboard.TargetName="myMatrixTransform"
Storyboard.TargetProperty="Matrix" DoesRotateWithTangent="True"
Duration="0:0:5" RepeatBehavior="Forever" AutoReverse="True">
<MatrixAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"/>
</MatrixAnimationUsingPath.PathGeometry>
</MatrixAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</WrapPanel>
</StackPanel>
</DockPanel>
</Page>
路径动画
最新推荐文章于 2024-04-22 13:21:41 发布