日期:2014-05-17  浏览次数:20812 次

WPF 旋转动画问题。xaml里能成功,cs类里写就报错

这是XAML的方式,能成功:
C# code

<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="image4">
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="30">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CircleEase EasingMode="EaseInOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>



这是CS代码的方式,要说属性错误:
C# code

DoubleAnimation daRotation = new DoubleAnimation();
                daRotation.From = rd.Next(360);
                daRotation.To = rd.Next(360);
                daRotation.EasingFunction = new CircleEase() { EasingMode = EasingMode.EaseInOut };
                daRotation.Duration = new TimeSpan(0, 0, 0, 0, 1500);
                Storyboard.SetTargetProperty(daRotation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
                Storyboard.SetTarget(daRotation, element);
                sb.Children.Add(daRotation);




百思不得其解啊。。。 大神们求助啊。。。

------解决方案--------------------
亲,试试在调用动画之前加一句
element.RenderTransform = new RotateTransform();