问题
I have three images, two of these images animate as follow and third image should blink:
<Window.Resources>
<Storyboard x:Key="AnimateTarget" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Duration="0:00:03" Storyboard.TargetName="img1" Storyboard.TargetProperty="Y">
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="200" />
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:2" Duration="0:00:03" Storyboard.TargetName="img2" Storyboard.TargetProperty="x">
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="200" />
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation BeginTime="0:0:4" Duration="0:0:0.5" Storyboard.TargetProperty="(Image.Opacity)" Storyboard.TargetName="img3" From="1.0" To="0.0" RepeatBehavior="Forever" AutoReverse="True" />
</Storyboard>
</Window.Resources>
The first two images are animating fine but the third image doesn’t blink, it will do nothing and just stay there as you can see I have used the following code for blinking the third image:
<DoubleAnimation BeginTime="0:0:4" Duration="0:0:0.5" Storyboard.TargetProperty="(Image.Opacity)" Storyboard.TargetName="img3" From="1.0" To="0.0" RepeatBehavior="Forever" AutoReverse="True" />
Also this is a code for the third image:
<Image Height="65" Name="image1" Stretch="Fill" Width="67" Source="/PicTakeWPF;component/Images/422505_110594629067212_100003500265268_37406_1212153553_n.jpg">
<Image.RenderTransform>
<TranslateTransform x:Name="img3"></TranslateTransform>
</Image.RenderTransform>
</Image>
I would appreciate if someone helps me on this Thanks,
回答1:
Try using the Name (image1) of your image object as Storyboard.TargetName for the opacity animation
<DoubleAnimation BeginTime="0:0:4" Duration="0:0:0.5" Storyboard.TargetProperty="(Image.Opacity)" Storyboard.TargetName="image1" From="1.0" To="0.0" RepeatBehavior="Forever" AutoReverse="True" />
because the opacity is a property of the image itself, the other 2 animations affect the translation of the image object and that's why you use the TranslateTransform name for those animations.
You don't even need to add
<Image.RenderTransform>
<TranslateTransform x:Name="img3"></TranslateTransform>
</Image.RenderTransform>
for the third image (if you're not planning on animating the translation).
来源:https://stackoverflow.com/questions/11146405/wpf-animate-and-change-opacity-of-image-in-sequence