首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-09-24 
WPF 旋转动画问题。xaml里能成功,cs类里写就报错这是XAML的方式,能成功:C# codeDoubleAnimationUsingKeyFr

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();

热点排行