前台代码:
<UserControl x:Class="story.MainPage" xmlns="" xmlns:x="" xmlns:d="" xmlns:mc="" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <UserControl.Resources > <Storyboard x:Name="sb"> <DoubleAnimation Storyboard.TargetName="rtf" Storyboard.TargetProperty="Angle" Duration="00:00:03" From="0" To="300"></DoubleAnimation> </Storyboard> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Image Name="img" Width="300" Height="300" Source="img/9.jpg" Stretch="Uniform" > <Image.RenderTransform > <RotateTransform x:Name="rtf"></RotateTransform> </Image.RenderTransform> </Image> <Button Name="btn" Width="100" Height="50" FontSize="24" Content="故事板" Click="btn_Click"></Button> </Grid> </UserControl>
我们只需在后台加一句代码就行了:
private void btn_Click(object sender, RoutedEventArgs e) { sb.Begin(); }
原文链接: