关键帧动画

<Page x:Class="关键帧动画.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowTitle="关键帧动画">
    <Canvas>
        <Ellipse Fill="Magenta" Width="50" Height="50" Canvas.Left="10" Canvas.Top="20">
            <Ellipse.RenderTransform>
                <TranslateTransform x:Name="tt" X="0" Y="0"/>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Rectangle Width="50" Height="50" Fill="Blue" Opacity="0.68" Canvas.Left="35" Canvas.Top="20" Name="MyRect"/>
        <Button Name="buttonCircleBegin" Canvas.Left="50" Canvas.Top="90">圆开始运动</Button>
        <Button Name="buttonCircleStop" Canvas.Left="130" Canvas.Top="90">圆停止运动</Button>
        <Button Name="buttonRectBegin" Canvas.Left="208" Canvas.Top="90">正方形开始运动</Button>
        <Button Name="buttonRectStop" Canvas.Left="310" Canvas.Top="90">正方形停止运动</Button>
        <Canvas.Triggers>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonCircleBegin">
                <BeginStoryboard Name="bsb1">
                    <Storyboard>
                        <!--动画过程先按给定值,给定的时间走一遍,结束后再反向走一遍-->
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="tt"
                                                       Storyboard.TargetProperty="X" Duration="0:0:10"
                                                       AutoReverse="True" RepeatBehavior="Forever">
                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
                            <LinearDoubleKeyFrame Value="386" KeyTime="0:0:2"/>
                            <LinearDoubleKeyFrame Value="50" KeyTime="0:0:5"/>
                            <LinearDoubleKeyFrame Value="200" KeyTime="0:0:8"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonCircleStop">
                <StopStoryboard BeginStoryboardName="bsb1"/>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonRectBegin">
                <BeginStoryboard Name="bsb2">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="MyRect" Storyboard.TargetProperty="(Canvas.Left)"
                                         From="100" To="360" Duration="0:0:10" AutoReverse="true" RepeatBehavior="Forever"/>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="MyRect" Storyboard.TargetProperty="(Canvas.Top)"
                                                       Duration="0:0:10" AutoReverse="True" RepeatBehavior="Forever">
                            <LinearDoubleKeyFrame Value="22" KeyTime="0:0:0"/>
                            <LinearDoubleKeyFrame Value="120" KeyTime="0:0:2"/>
                            <LinearDoubleKeyFrame Value="22" KeyTime="0:0:6"/>
                            <LinearDoubleKeyFrame Value="120" KeyTime="0:0:8"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonRectStop">
                <StopStoryboard BeginStoryboardName="bsb2"/>
            </EventTrigger>
        </Canvas.Triggers>
    </Canvas>
</Page>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值