uwp 動畫Storyboard

代碼以下:動畫

 <Page.Resources>
        <Storyboard x:Name="storyboard">
            <DoubleAnimation Storyboard.TargetName="rect"
                             Storyboard.TargetProperty="(Canvas.Left)"
                             By="300"
                             Duration="0:0:2"
                             AutoReverse="True"
                             RepeatBehavior="Forever"></DoubleAnimation>         
        </Storyboard>
    </Page.Resources>get

 

 <Canvas Background="Azure"
                Width="600"
                Height="400">
            <Rectangle x:Name="rect"
                       Fill="Red"
                       Width="100"
                       Height="50"></Rectangle>
            <Button Canvas.Top="50"
                    Width="100"
                    Height="50"
                    Content="go"
                    Click="Button_Click_1"></Button>       
        </Canvas>io

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            storyboard.Begin();
        }object

 

第一次接觸到動畫效果,感受很神奇,經過Storyboard,DoubleAnimation修改項要變化的屬性 ,同時設置位置和時間參數,便可達到效果。im

相關文章
相關標籤/搜索