コード例 #1
0
ファイル: GridContext.xaml.cs プロジェクト: dingxinbei/OLdBck
        private void InitBubbleAn(CustomControls.Bubbles bb)
        {
            //Canvas.SetBottom(bb, -bb.ActualHeight / 2);
            //Canvas.SetRight(bb, -bb.ActualWidth / 2);

            bb.RenderTransformOrigin = new Point(0.5, 0.5);
            bb.RandomColors();
            TranslateTransform translate = new TranslateTransform();
            //RotateTransform rotate = new RotateTransform();
            TransformGroup group = (TransformGroup)bb.RenderTransform;
            //group.Children.Add(rotate);//先旋转
            group.Children.Add(translate);//再平移
            //ScaleTransform st = new ScaleTransform(0.1, 0.1);
            //group.Children.Add(st);
            bb.RenderTransform = group;

            NameScope.SetNameScope(this, new NameScope());
            this.RegisterName("translate", translate);
            //this.RegisterName("rotate", rotate);

            //Path p = new Path();
            //p.Data = (PathGeometry)PathGeometry.Parse("M416,752 C416.62132,721.83583 376.22793,703.51499 417.86397,661.5075 459.5,619.5 418.99008,606.83656 419.55313,579.50109 420.17109,549.50009 385.31468,541.49617 421.40702,489.49808 457.49935,437.5 422.80709,421.52692 423.50712,387.54134 424.0839,359.53949 388.9757,351.57158 425.23747,303.53579 461.49924,255.5 426.58377,238.17526 427.25691,205.49499 427.77851,180.1724 372.14433,181.55445 428.8217,129.52722 485.49907,77.5 429.94781,74.856289
430.51087,47.520822 430.84058,31.513881 387.50032,25.5 431.5,-0.5");
            //PathGeometry p = new PathGeometry();
            //p = (PathGeometry)PathGeometry.Parse("M416,752 C416.62132,721.83583 376.22793,703.51499 417.86397,661.5075 459.5,619.5 418.99008,606.83656 419.55313,579.50109 420.17109,549.50009 385.31468,541.49617 421.40702,489.49808 457.49935,437.5 422.80709,421.52692 423.50712,387.54134 424.0839,359.53949 388.9757,351.57158 425.23747,303.53579 461.49924,255.5 426.58377,238.17526 427.25691,205.49499 427.77851,180.1724 372.14433,181.55445 428.8217,129.52722 485.49907,77.5 429.94781,74.856289
430.51087,47.520822 430.84058,31.513881 387.50032,25.5 431.5,-0.5");
            DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath();
            animationX.PathGeometry = p.Data.GetFlattenedPathGeometry();
            animationX.Source = PathAnimationSource.X;
            animationX.Duration = new Duration(TimeSpan.FromSeconds(2));

            DoubleAnimationUsingPath animationY = new DoubleAnimationUsingPath();
            animationY.PathGeometry = p.Data.GetFlattenedPathGeometry();
            animationY.Source = PathAnimationSource.Y;
            animationY.Duration = animationX.Duration;

            //DoubleAnimationUsingPath animationAngle = new DoubleAnimationUsingPath();
            //animationAngle.PathGeometry = p.Data.GetFlattenedPathGeometry();
            //animationAngle.Source = PathAnimationSource.Angle;
            //animationAngle.Duration = animationX.Duration;

            Storyboard story = new Storyboard();
            story.RepeatBehavior = RepeatBehavior.Forever;
            //story.AutoReverse = true;
            story.SpeedRatio = 0.1 + 0.3 * gRr.NextDouble();
            story.Children.Add(animationX);
            story.Children.Add(animationY);
            //story.Children.Add(animationAngle);
            Storyboard.SetTargetName(animationX, "translate");
            Storyboard.SetTargetName(animationY, "translate");
            //Storyboard.SetTargetName(animationAngle, "rotate");
            Storyboard.SetTargetProperty(animationX, new PropertyPath(TranslateTransform.XProperty));
            Storyboard.SetTargetProperty(animationY, new PropertyPath(TranslateTransform.YProperty));
            //Storyboard.SetTargetProperty(animationAngle, new PropertyPath(RotateTransform.AngleProperty));
            //story.Completed += new EventHandler(story_Completed);
            story.Begin(this);
        }