使用故事板在动画期间更改图像 [英] Change an image during animation using storyboard
问题描述
我正在寻找一种在故事板中更改图像的方法,或者更具体地说,将图像的 Source
属性更改为指向到新的图像资源。似乎有一个 StringAnimationUsingKeyFrames
和一个 DiscreteStringKeyFrame
但这不起作用(据我所知),因为Image的Source属性类型为 ImageSource
I was looking for a way to change an Image during a storyboard, or more specifically, change the Source
property of the image to point to a new image resource. There seems to be a StringAnimationUsingKeyFrames
and a DiscreteStringKeyFrame
but this does not work (as far as I can tell) since the Source property of the Image is of type ImageSource
我当前的故事板看起来像这样
My current storyboard looks like this
<Storyboard x:Key="TransitionImage">
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="image"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0.2"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<StringAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="image"
Storyboard.TargetProperty="(Image.Source)">
<!-- This does not work -->
<DiscreteStringKeyFrame KeyTime="00:00:00.7000000" Value="check_24.png"/>
</StringAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="image"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0.2"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
和图片
<Image x:Name="image"
Source="delete_24.png"
Width="32" Height="32"
Margin="8"
RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
我可以更改图片的来源
作为故事板的一部分还是我运气不好?
Can I change the Source
of the image as part of the storyboard or am I out of luck?
推荐答案
好的,我自己解决了。似乎你必须使用 ObjectAnimationUsingKeyFrames
和 DiscreteObjectKeyFrame
,如下所示:
Okay, solved it myself. Seems you have to use the ObjectAnimationUsingKeyFrames
and DiscreteObjectKeyFrame
as shown below:
<ObjectAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="image"
Storyboard.TargetProperty="(Image.Source)">
<DiscreteObjectKeyFrame KeyTime="00:00:00.7000000">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="check_24.png" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
这篇关于使用故事板在动画期间更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!