GroupTransform 中的动画变换问题
我在 WPF 项目(后面是 VB.net 代码)中有一张鱼的图像,我尝试使用两个变换来制作它来回游动的动画。
由于某种原因,如果我只对 ScaleTransform 进行动画处理(仅使用 ScaleTransform,而不使用 TransformGroup),则动画可以正常工作,但 TranslateTransform 动画则不能。此外,ScaleTransform 在 TransformGroup 内部时不起作用。
这是我正在使用的代码。我做错了什么?
<Image Height="90" HorizontalAlignment="Left" Name="Fish1" Stretch="Fill" VerticalAlignment="Top" Width="260" Source="/VBP-WORD4WORD;component/Images/IMG-FISH1.png" Canvas.Left="24" Canvas.Top="67" Margin="-28,70,0,0">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1"/>
<TranslateTransform X="0"/>
</TransformGroup>
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Duration="0:0:30" Storyboard.TargetProperty="RenderTransform.(TransformGroup.TranslateTransform.X)" RepeatBehavior="Forever">
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:14.9" Value="407"/>
<LinearDoubleKeyFrame KeyTime="0:0:15" Value="680"/>
<LinearDoubleKeyFrame KeyTime="0:0:29.9" Value="265"/>
<LinearDoubleKeyFrame KeyTime="0:0:30" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Duration="0:0:30" Storyboard.TargetProperty="RenderTransform.(TransformGroup.ScaleTransform.ScaleX)" RepeatBehavior="Forever">
<LinearDoubleKeyFrame KeyTime="0:0:14.9" Value="1"/>
<LinearDoubleKeyFrame KeyTime="0:0:15" Value="-1"/>
<LinearDoubleKeyFrame KeyTime="0:0:29.9" Value="-1"/>
<LinearDoubleKeyFrame KeyTime="0:0:30" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
</Image>
I have an image of a fish in a WPF project (VB.net code behind), and I'm attempting to animate it swimming back and forth using two transforms.
For some reason, while if I only animate the ScaleTransform (with ScaleTransform alone, and no TransformGroup), the animation works fine, the TranslateTransform animation does not. Additionally, the ScaleTransform does not work when inside the TransformGroup.
Here is the code I'm using. What am I doing wrong?
<Image Height="90" HorizontalAlignment="Left" Name="Fish1" Stretch="Fill" VerticalAlignment="Top" Width="260" Source="/VBP-WORD4WORD;component/Images/IMG-FISH1.png" Canvas.Left="24" Canvas.Top="67" Margin="-28,70,0,0">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1"/>
<TranslateTransform X="0"/>
</TransformGroup>
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Duration="0:0:30" Storyboard.TargetProperty="RenderTransform.(TransformGroup.TranslateTransform.X)" RepeatBehavior="Forever">
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:14.9" Value="407"/>
<LinearDoubleKeyFrame KeyTime="0:0:15" Value="680"/>
<LinearDoubleKeyFrame KeyTime="0:0:29.9" Value="265"/>
<LinearDoubleKeyFrame KeyTime="0:0:30" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Duration="0:0:30" Storyboard.TargetProperty="RenderTransform.(TransformGroup.ScaleTransform.ScaleX)" RepeatBehavior="Forever">
<LinearDoubleKeyFrame KeyTime="0:0:14.9" Value="1"/>
<LinearDoubleKeyFrame KeyTime="0:0:15" Value="-1"/>
<LinearDoubleKeyFrame KeyTime="0:0:29.9" Value="-1"/>
<LinearDoubleKeyFrame KeyTime="0:0:30" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
</Image>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些属性路径都是错误的,但我会投票赞成通过利用
Storyboard.TargetName
来避免仅使用这些路径的整个麻烦;这是有效的:如果您真的想仅使用 Storyboard.TargetProperty 来完成此操作,那么这些将是我刚才发现的正确路径:
如果您考虑一下,这确实很有意义。
Those property paths are all wrong, but i would vote for just avoiding the whole trouble of only using those paths by utilizing
Storyboard.TargetName
; this works:If you really want to do it using
Storyboard.TargetProperty
only, these would be the correct paths as i found out just now:Which does make perfect sense if you think about it.