Trouble Animating Transforms in GroupTransform

后端 未结 1 1247
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 16:48

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

相关标签:
1条回答
  • 2021-02-14 17:17

    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:

    <!-- ... -->
    <TransformGroup>
        <ScaleTransform  x:Name="scaleTransform" ScaleX="1"/>
        <TranslateTransform x:Name="translateTransform" X="0"/>
    </TransformGroup>
      <!-- ... -->
        <Storyboard>
            <DoubleAnimationUsingKeyFrames Duration="0:0:30"
                                           Storyboard.TargetProperty="ScaleX"
                                           Storyboard.TargetName="scaleTransform"
                                           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>
            <DoubleAnimationUsingKeyFrames Duration="0:0:30"
                                           Storyboard.TargetProperty="X"
                                           Storyboard.TargetName="translateTransform"
                                           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>
        </Storyboard>
    

    If you really want to do it using Storyboard.TargetProperty only, these would be the correct paths as i found out just now:

    Storyboard.TargetProperty="RenderTransform.Children[0].ScaleX"
    Storyboard.TargetProperty="RenderTransform.Children[1].X"
    

    Which does make perfect sense if you think about it.

    0 讨论(0)
提交回复
热议问题