路径动画

<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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值