效果图:
这次使用Animation来旋转图片.这里面有一个问题,后台代码访问资源字典里面的name属性访问不到.
前台代码:
<Window.Resources>
<Storyboard Name="sb1" x:Key="xxk">
<DoubleAnimation Storyboard.TargetName="image1" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:10"></DoubleAnimation>
</Storyboard>
</Window.Resources>
<Grid>
<Image HorizontalAlignment="Left" Height="240" Width="240" Margin="144,44,0,0" VerticalAlignment="Top" Source="no.jpg">
<Image.RenderTransform>
<RotateTransform CenterX="120" CenterY="120" Angle="10" x:Name="image1"></RotateTransform>
</Image.RenderTransform>
</Image>
</Grid>
经过多次实验.不知道为什么,this.Resources.FindName不行.不过用this.findResource就可以了.
后台代码:
//这个好像不行
// Storyboard sb= (Storyboard)this.Resources.FindName("sb1");
Storyboard sb1=(Storyboard)this.FindResource("xxk");
sb1.Begin();