读书人

怎么用c#写PlaneProjection.RotationY

发布时间: 2012-04-13 13:50:24 作者: rapoo

如何用c#写PlaneProjection.RotationY的动画呢

C# code
DoubleAnimation da = new DoubleAnimation()                {                    Duration = TimeSpan.FromSeconds(0.5),                    To = 50                };                Storyboard sb = new Storyboard();                Storyboard.SetTarget(da, this.myCavas);                Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));//如果里边换成Height,Width都是可以的。                sb.Children.Add(da);                sb.Begin();

测试了,这样不行呀。如果做高度,或者是宽度的动画,都是可以的。

错误提示:无法解析指定对象的 TargetProperty (UIElement.Projection).(PlaneProjection.RotationY)。

我用谷歌搜索了下,找到一堆代码也是不行。
C# code
Storyboard storyTest = new Storyboard();                DoubleAnimationUsingKeyFrames _new_rotate = new DoubleAnimationUsingKeyFrames();                EasingDoubleKeyFrame _frame1 = new EasingDoubleKeyFrame();                _frame1.Value = 180;                _frame1.KeyTime = new TimeSpan(0, 0, 0, 1);                EasingDoubleKeyFrame _frame2 = new EasingDoubleKeyFrame();                _frame2.Value = 0;                _frame2.KeyTime = new TimeSpan(0, 0, 0, 2);                EasingDoubleKeyFrame _frame3 = new EasingDoubleKeyFrame();                _frame3.Value = 90;                _frame3.KeyTime = new TimeSpan(0, 0, 0, 5);                _new_rotate.KeyFrames.Add(_frame1);                _new_rotate.KeyFrames.Add(_frame2);                _new_rotate.KeyFrames.Add(_frame3);                storyTest.Children.Add(_new_rotate);                Storyboard.SetTarget(_new_rotate, this.myCavas);                Storyboard.SetTargetProperty(_new_rotate, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));                storyTest.AutoReverse = false;                //storyTest.FillBehavior = FillBehavior.Stop;//加入这一行后,不管AutoReverse设置为何值,都会回复原状                            storyTest.Begin();


[解决办法]
我来挣你的分
silverlight3.0测试通过

C# code
         Canvas c;     void btnDraw_Click(object sender, RoutedEventArgs e)        {            Storyboard story = new Storyboard();            DoubleAnimation yAnimation = new DoubleAnimation();            yAnimation.From = 0.5;            yAnimation.To = 100;            yAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));            PlaneProjection pp = (PlaneProjection)c.Projection; //找到你注册的属性              Storyboard.SetTarget(yAnimation, pp);            Storyboard.SetTargetProperty(yAnimation, new PropertyPath(PlaneProjection.RotationYProperty));            story.Children.Add(yAnimation); story.Begin();         }        void MainPage_Loaded(object sender, RoutedEventArgs e)        {            c = new Canvas();            c.Height = 200;            c.Width = 200;            c.Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));            PlaneProjection pp = new PlaneProjection() { RotationY = 0 };//这里已经指定了RotationY            c.Projection = pp;            LayoutRoot.Children.Add(c);        } 

读书人网 >CAD教程

热点推荐