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>
<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>
private void Button_Click_1(object sender, RoutedEventArgs e)
{
storyboard.Begin();
}
第一次接触到动画效果,感觉很神奇,通过Storyboard,DoubleAnimation修改项要变化的属性 ,同时设置位置和时间参数,即可达到效果。