在GroupTransform麻烦动画变换 [英] Trouble Animating Transforms in GroupTransform

查看:119
本文介绍了在GroupTransform麻烦动画变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条鱼的图像中的WPF项目(VB.net code后面),而我试图动画它来回游动使用两个变换。

由于某些原因,而如果我只是动画ScaleTransform(单独ScaleTransform,没有的TransformGroup),动画作品精细,TranslateTransform动画没有。此外,ScaleTransform不会在的TransformGroup内时工作。

下面是code我使用。我在做什么错了?

 <图像高度=90的Horizo​​ntalAlignment =左NAME =Fish1拉伸=填充VerticalAlignment =评出的WIDTH =260来源=/ VBP -WORD4WORD;组件/图片/ IMG-FISH1.pngCanvas.Left =24Canvas.Top =67保证金= -  28,70,0,0>
    < Image.RenderTransform>
        <&的TransformGroup GT;
            &所述; ScaleTransform的ScaleX =1/>
            &所述; TranslateTransform x =0/>
        < /&的TransformGroup GT;
    < /Image.RenderTransform>
    < Image.Triggers>
        <的EventTrigger RoutedEvent =Image.Loaded>
            < EventTrigger.Actions>
                < BeginStoryboard>
                    <情节提要>
                        < D​​oubleAnimationUsingKeyFrames持续时间=0:0:30Storyboard.TargetProperty =的RenderTransform(TransformGroup.TranslateTransform.X)的repeatBehavior =永远>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:0值=0/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:14.9值=407/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:15值=680/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:29.9值=265/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:30值=0/>
                        < / DoubleAnimationUsingKeyFrames>
                        < D​​oubleAnimationUsingKeyFrames持续时间=0:0:30Storyboard.TargetProperty =的RenderTransform(TransformGroup.ScaleTransform.ScaleX)的repeatBehavior =永远>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:14.9值=1/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:15值= - 1/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:29.9值= - 1/>
                            &所述; LinearDoubleKeyFrame KeyTime =0:0:30值=1/>
                        < / DoubleAnimationUsingKeyFrames>
                    < /故事板>
                < / BeginStoryboard>
            < /EventTrigger.Actions>
        < /&的EventTrigger GT;
    < /Image.Triggers>
< /图像>


解决方案

这些财产的路径都是错误的,但我会投票只是避免使用只有那些路径利用 Storyboard.TargetName整个麻烦;这个作品:

 <! -  ...  - >
<&的TransformGroup GT;
    &所述; ScaleTransform X:名称=scaleTransform的ScaleX =1/>
    &所述; TranslateTransform X:名称=translateTransformX =0/>
< /&的TransformGroup GT;
  <! - ... - >
    <情节提要>
        &所述; DoubleAnimationUsingKeyFrames持续时间=0:0:30
                                       Storyboard.TargetProperty =的ScaleX
                                       Storyboard.TargetName =scaleTransform
                                       的repeatBehavior =永远>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:14.9值=1/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:15值= - 1/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:29.9值= - 1/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:30值=1/>
        < / DoubleAnimationUsingKeyFrames>
        &所述; DoubleAnimationUsingKeyFrames持续时间=0:0:30
                                       Storyboard.TargetProperty =X的
                                       Storyboard.TargetName =translateTransform
                                       的repeatBehavior =永远>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:0值=0/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:14.9值=407/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:15值=680/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:29.9值=265/>
            &所述; LinearDoubleKeyFrame KeyTime =0:0:30值=0/>
        < / DoubleAnimationUsingKeyFrames>
    < /故事板>

如果你真的想使用 Storyboard.TargetProperty 只是,这些将是正确的路径,做到这一点,因为我刚才发现:

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

这确实让完美的意义,如果你考虑一下吧。

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>

解决方案

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.

这篇关于在GroupTransform麻烦动画变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆