private void Validate() { Debug.Assert(!_isValid); if (IsOffsetCumulative || IsAngleCumulative) { Point startPoint; Point startTangent; Point endPoint; Point endTangent; PathGeometry pathGeometry = PathGeometry; // Get values at the beginning of the path. pathGeometry.GetPointAtFractionLength(0.0, out startPoint, out startTangent); // Get values at the end of the path. pathGeometry.GetPointAtFractionLength(1.0, out endPoint, out endTangent); // Calculate difference. _accumulatingAngle = DoubleAnimationUsingPath.CalculateAngleFromTangentVector(endTangent.X, endTangent.Y) - DoubleAnimationUsingPath.CalculateAngleFromTangentVector(startTangent.X, startTangent.Y); _accumulatingOffset.X = endPoint.X - startPoint.X; _accumulatingOffset.Y = endPoint.Y - startPoint.Y; } _isValid = true; }
/// <summary> /// Create the animation and add it to the master timeline /// </summary> protected override void CreateAnimation() { var geometry = new PathGeometry(); geometry.AddGeometry(Geometry.Parse("M 10,100 C 10,300 300,-200 300,100")); var animationX = new DoubleAnimationUsingPath { PathGeometry = geometry, Duration = new Duration(this.AnimationConfiguration.Duration), Source = PathAnimationSource.X }; var animationY = new DoubleAnimationUsingPath { PathGeometry = geometry, Duration = new Duration(this.AnimationConfiguration.Duration), Source = PathAnimationSource.Y }; Storyboard.SetTargetProperty(animationX, new PropertyPath(Canvas.LeftProperty)); Storyboard.SetTargetProperty(animationY, new PropertyPath(Canvas.TopProperty)); animationX.Freeze(); animationY.Freeze(); this.MasterStoryboard.Children.Add(animationX); this.MasterStoryboard.Children.Add(animationY); }
public void MoveImage(TimeSpan interval, PathGeometry beeFlyHerePath) { var storyboard = new Storyboard { RepeatBehavior = RepeatBehavior.Forever }; var moveCircleAnimation = new DoubleAnimationUsingPath { PathGeometry = beeFlyHerePath, Source = PathAnimationSource.X, Duration = interval }; Storyboard.SetTarget(moveCircleAnimation, this); Storyboard.SetTargetProperty(moveCircleAnimation, new PropertyPath("(Canvas.Left)")); var moveCircleAnimation2 = new DoubleAnimationUsingPath { PathGeometry = beeFlyHerePath, Source = PathAnimationSource.Y, Duration = interval }; Storyboard.SetTarget(moveCircleAnimation2, this); Storyboard.SetTargetProperty(moveCircleAnimation2, new PropertyPath("(Canvas.Top)")); storyboard.Children.Add(moveCircleAnimation); storyboard.Children.Add(moveCircleAnimation2); storyboard.Begin(); }
/// <summary> /// Calculates the value this animation believes should be the current value for the property. /// </summary> /// <param name="defaultOriginValue"> /// This value is the suggested origin value provided to the animation /// to be used if the animation does not have its own concept of a /// start value. If this animation is the first in a composition chain /// this value will be the snapshot value if one is available or the /// base property value if it is not; otherise this value will be the /// value returned by the previous animation in the chain with an /// animationClock that is not Stopped. /// </param> /// <param name="defaultDestinationValue"> /// This value is the suggested destination value provided to the animation /// to be used if the animation does not have its own concept of an /// end value. This value will be the base value if the animation is /// in the first composition layer of animations on a property; /// otherwise this value will be the output value from the previous /// composition layer of animations for the property. /// </param> /// <param name="animationClock"> /// This is the animationClock which can generate the CurrentTime or /// CurrentProgress value to be used by the animation to generate its /// output value. /// </param> /// <returns> /// The value this animation believes should be the current value for the property. /// </returns> protected override Matrix GetCurrentValueCore(Matrix defaultOriginValue, Matrix defaultDestinationValue, AnimationClock animationClock) { Debug.Assert(animationClock.CurrentState != ClockState.Stopped); PathGeometry pathGeometry = PathGeometry; if (pathGeometry == null) { return(defaultDestinationValue); } if (!_isValid) { Validate(); } Point pathPoint; Point pathTangent; pathGeometry.GetPointAtFractionLength(animationClock.CurrentProgress.Value, out pathPoint, out pathTangent); double angle = 0.0; if (DoesRotateWithTangent) { angle = DoubleAnimationUsingPath.CalculateAngleFromTangentVector(pathTangent.X, pathTangent.Y); } Matrix matrix = new Matrix(); double currentRepeat = (double)(animationClock.CurrentIteration - 1); if (currentRepeat > 0) { if (IsOffsetCumulative) { pathPoint = pathPoint + (_accumulatingOffset * currentRepeat); } if (DoesRotateWithTangent && IsAngleCumulative) { angle = angle + (_accumulatingAngle * currentRepeat); } } matrix.Rotate(angle); matrix.Translate(pathPoint.X, pathPoint.Y); if (IsAdditive) { return(Matrix.Multiply(matrix, defaultOriginValue)); } else { return(matrix); } }
private void Test_Double() { Canvas.SetTop(this.border1, -this.border1.ActualHeight / 2); Canvas.SetLeft(this.border1, -this.border1.ActualWidth / 2); this.border1.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translate = new TranslateTransform(); RotateTransform rotate = new RotateTransform(); TransformGroup group = new TransformGroup(); group.Children.Add(rotate);//先旋转 group.Children.Add(translate);//再平移 this.border1.RenderTransform = group; NameScope.SetNameScope(this, new NameScope()); this.RegisterName("translate", translate); this.RegisterName("rotate", rotate); DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath(); animationX.PathGeometry = this.path1.Data.GetFlattenedPathGeometry(); animationX.Source = PathAnimationSource.X; animationX.Duration = new Duration(TimeSpan.FromSeconds(2)); DoubleAnimationUsingPath animationY = new DoubleAnimationUsingPath(); animationY.PathGeometry = this.path1.Data.GetFlattenedPathGeometry(); animationY.Source = PathAnimationSource.Y; animationY.Duration = animationX.Duration; DoubleAnimationUsingPath animationAngle = new DoubleAnimationUsingPath(); animationAngle.PathGeometry = this.path1.Data.GetFlattenedPathGeometry(); animationAngle.Source = PathAnimationSource.Angle; animationAngle.Duration = animationX.Duration; Storyboard story = new Storyboard(); story.RepeatBehavior = RepeatBehavior.Forever; story.AutoReverse = true; 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.Begin(this); }
private void AnimateMoveBall(Ball ball, Cell fromCell, Cell toCell) { List<Point> path = _table.FindPath(fromCell, toCell).Select(c => c.BallPoint).ToList(); _table.StartMoveBallTo(ball, toCell); TimeSpan duration = TimeSpan.FromSeconds(AnimMovingBallStep * path.Count); DoubleAnimationUsingPath animX; _animMovingBall = new Storyboard { Children = { (animX = new DoubleAnimationUsingPath { PathGeometry = new PathGeometry { Figures = new PathFigureCollection { new PathFigure(fromCell.BallPoint, path.Select(p => new LineSegment(p, false)), false) } }, Duration = new Duration(duration), AccelerationRatio = .1, DecelerationRatio = .7, Source = PathAnimationSource.X, }.SetTarget(Canvas.LeftProperty.ToPath())), animX.CloneForY().SetTarget(Canvas.TopProperty.ToPath()), } }; _animMovingBall.AddCompleted(AnimMove_OnCompleted).Begin(lstBalls.GetItemContainer(toCell.Ball)); }
public static void MoveUIElement(StackPanel control, double displacement) { DoubleAnimationUsingPath da = new DoubleAnimationUsingPath(); da.Duration = time; da.DecelerationRatio = acceleration; PathGeometry pg = new PathGeometry(); PathFigure pf = new PathFigure(); pf.StartPoint = new Point(control.Margin.Left, control.Margin.Top); PolyBezierSegment pbs = new PolyBezierSegment(); for(int i = 0; i < displacement; i++) pbs.Points.Add(new Point(control.Margin.Left, control.Margin.Top - i)); pf.Segments.Add(pbs); pg.Figures.Add(pf); da.PathGeometry = pg; da.Source = PathAnimationSource.X; Storyboard sb = new Storyboard(); sb.Children.Add(da); sb.Begin(control); }
private void TerminalLoad(object sender, RoutedEventArgs e) { System.Windows.Forms.Cursor.Hide(); //Debug.WriteLine("staaart!"); int Width = SystemInformation.PrimaryMonitorSize.Width; int Height = SystemInformation.PrimaryMonitorSize.Height; DockPanel MainDockPanel = new DockPanel(); this.MainGrid.Children.Add(MainDockPanel); MainDockPanel.VerticalAlignment = VerticalAlignment.Top; LinearGradientBrush GreenGradientBrush = new LinearGradientBrush(); GreenGradientBrush.GradientStops.Add(new GradientStop(Colors.Green, 0.0)); GreenGradientBrush.GradientStops.Add(new GradientStop(Colors.White, 0.5)); GreenGradientBrush.GradientStops.Add(new GradientStop(Colors.Green, 1.0)); this.Advertismen.Background = GreenGradientBrush; DockPanel.SetDock(this.Advertismen, Dock.Top); MainDockPanel.LastChildFill = true; MainDockPanel.Children.Add(this.Advertismen); this.Advertismen.Width = (double)Width; this.Advertismen.Height = (double)(Height / 10); DockPanel LeftGrid = new DockPanel(); Grid RightGrid = new Grid(); DockPanel.SetDock(LeftGrid, Dock.Left); DockPanel.SetDock(RightGrid, Dock.Right); LeftGrid.Background = GreenGradientBrush; RightGrid.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("sampleImages\\главная фоновое.jpg", UriKind.Relative)) }; this.MoveGridWidth = Width / 10 * 7; this.MoveGridHidth = Height / 10 * 9; this.RightInputGrid.Width = (double)(Width / 10 * 7 / 2); this.RightInputGrid.Height = (double)(Height / 10 * 9); this.RightInputGrid.Children.Add(this.Text); this.Text.TextWrapping = TextWrapping.Wrap; this.Text.FontSize = 20.0; this.RightInputGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; this.RightInputGrid.Background = new SolidColorBrush(Color.FromArgb(0, 255, 255, 255)); this.RightInputGridLeft.Width = (double)(Width / 10 * 7 / 2); this.RightInputGridLeft.Height = (double)(Height / 10 * 9); this.RightInputGridLeft.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; this.MoveGrid.Children.Add(this.RightInputGridLeft); MainDockPanel.Children.Add(LeftGrid); MainDockPanel.Children.Add(RightGrid); LeftGrid.Height = (double)(Height / 10 * 9); RightGrid.Height = (double)(Height / 10 * 9); LeftGrid.Width = (double)(Width / 10 * 3); RightGrid.Width = (double)(Width / 10 * 7); System.Windows.Controls.ListBox GroupList = new System.Windows.Controls.ListBox(); LeftGrid.Children.Add(this.GroupGrid); LeftGrid.Children.Add(this.RecipeGrid); DockPanel.SetDock(this.GroupGrid, Dock.Top); DockPanel.SetDock(this.RecipeGrid, Dock.Bottom); this.GroupGrid.Height = LeftGrid.Height / 2.0; this.RecipeGrid.Height = LeftGrid.Height / 2.0; this.GroupGrid.Width = LeftGrid.Width; this.RecipeGrid.Width = LeftGrid.Width; AdvertismentTxt = new TextBlock(); setAdvertismentText("Березинский биосферный заповедник"); menuLevel = 0; //AdvertismentTxt.Text = "Березинский биосферный заповедник"; //AdvertismentTxt.VerticalAlignment = VerticalAlignment.Center; //AdvertismentTxt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; //AdvertismentTxt.TextAlignment = TextAlignment.Center; //AdvertismentTxt.FontFamily = new FontFamily("Arial Black"); //AdvertismentTxt.TextWrapping = TextWrapping.Wrap; //AdvertismentTxt.BitmapEffect = new BevelBitmapEffect(); AdvertismentTxt.FontSize = 32.0; this.Advertismen.Children.Add(AdvertismentTxt); this.GroupGrid.Children.Add(this.GroupListBox); //TextBlock[] tb = new TextBlock[6]; //for (int i = 0; i < 6; i++ ) //{ // tb[i] = new TextBlock(); // tb[i].FontFamily = new FontFamily("Arial Black"); // tb[i].FontSize = 14; //} //MyListBoxItem itm = new MyListBoxItem(new FontFamily("Arial Black"), "О заповеднике"); //itm.Style. //this.GroupListBox.Items.Add(new MyListBoxItem(new FontFamily("Arial Black"), "Природные условия")); //this.GroupListBox.Items.Add(new MyListBoxItem(new FontFamily("Arial Black"), "Деятельность заповедника")); //this.GroupListBox.Items.Add(new MyListBoxItem(new FontFamily("Arial Black"), "Экологические маршруты")); //this.GroupListBox.Items.Add(new MyListBoxItem(new FontFamily("Arial Black"), "Экологическое просвещение")); //this.GroupListBox.Items.Add(new MyListBoxItem(new FontFamily("Arial Black"), "Туристические услуги")); //this.GroupListBox.Items.Add(new MyListBoxItem(new FontFamily("Arial Black"), "Контактная информация")); //ListBoxItem itm; //Style st = new Style() //itm.Style //tb[0].Text = "О заповеднике"; //this.GroupListBox.Items.Add(tb[0]); //tb[1].Text = "Природные условия"; //this.GroupListBox.Items.Add(tb[1]); //tb[2].Text = "Деятельность заповедника"; //this.GroupListBox.Items.Add(tb[2]); //tb[3].Text = "Экологические маршруты"; //this.GroupListBox.Items.Add(tb[3]); //tb[4].Text = "Экологическое просвещение"; //this.GroupListBox.Items.Add(tb[4]); //tb[5].Text = "Контактная информация"; //this.GroupListBox.Items.Add(tb[5]); //System.Windows.Forms.ListView lv = new System.Windows.Forms.ListView; this.GroupListBox.Items.Add("О заповеднике"); this.GroupListBox.Items.Add("Природные условия"); this.GroupListBox.Items.Add("Деятельность заповедника"); this.GroupListBox.Items.Add("Экологические маршруты"); this.GroupListBox.Items.Add("Экологическое просвещение"); this.GroupListBox.Items.Add("Туристические услуги"); this.GroupListBox.Items.Add("Контактная информация"); this.SmallImageListBox.Height = LeftGrid.Height / 2.0; this.SmallImageListBox.Width = LeftGrid.Width - 5.0; RightGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; this.SmallImageListBox.VerticalAlignment = VerticalAlignment.Top; this.SmallImageListBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; this.GroupListBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; this.GroupListBox.VerticalAlignment = VerticalAlignment.Top; this.GroupListBox.SelectionChanged += new SelectionChangedEventHandler(this.GroupListBox_SelectionChanged); this.SmallImageListBox.SelectionChanged += new SelectionChangedEventHandler(this.SmallImageListBox_SelectionChanged); RightGrid.Children.Add(this.MoveGrid); this.MoveGrid.Height = RightGrid.Height; this.MoveGrid.Width = RightGrid.Width; DoubleAnimation MoveAnimation = new DoubleAnimation(); MoveAnimation.Duration = TimeSpan.FromSeconds(5.0); MoveAnimation.From = new double?((double)Width); MoveAnimation.To = new double?(base.Width + 100.0); MoveAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500.0)); TranslateTransform TransformMove = new TranslateTransform(); MoveAnimation.By = new double?(0.2); this.MoveGrid.Children.Add(this.RightInputGrid); this.Img.Height = this.MoveGrid.Height; this.Img.Width = this.MoveGrid.Width; RotateTransform animatedRotateTransform = new RotateTransform(); TranslateTransform animatedTranslateTransform = new TranslateTransform(); base.RegisterName("AnimatedRotateTransform", animatedRotateTransform); base.RegisterName("AnimatedTranslateTransform", animatedTranslateTransform); TransformGroup tGroup = new TransformGroup(); tGroup.Children.Add(animatedRotateTransform); tGroup.Children.Add(animatedTranslateTransform); this.MoveGrid.RenderTransform = tGroup; PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); pFigure.StartPoint = new Point(0.0, 0.0); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pBezierSegment.Points.Add(new Point(RightGrid.Width, 0.0)); pBezierSegment.Points.Add(new Point(300.0, 0.0)); pBezierSegment.Points.Add(new Point(RightGrid.Width, 0.0)); pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); animationPath.Freeze(); DoubleAnimationUsingPath angleAnimation = new DoubleAnimationUsingPath(); angleAnimation.PathGeometry = animationPath; angleAnimation.Duration = TimeSpan.FromMilliseconds(500.0); angleAnimation.Source = PathAnimationSource.Angle; Storyboard.SetTargetName(angleAnimation, "AnimatedRotateTransform"); Storyboard.SetTargetProperty(angleAnimation, new PropertyPath(RotateTransform.AngleProperty)); DoubleAnimationUsingPath translateXAnimation = new DoubleAnimationUsingPath(); translateXAnimation.PathGeometry = animationPath; translateXAnimation.Duration = TimeSpan.FromMilliseconds(500.0); translateXAnimation.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation, "AnimatedTranslateTransform"); Storyboard.SetTargetProperty(translateXAnimation, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation = new DoubleAnimationUsingPath(); translateYAnimation.PathGeometry = animationPath; translateYAnimation.Duration = TimeSpan.FromMilliseconds(500.0); translateYAnimation.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation, "AnimatedTranslateTransform"); Storyboard.SetTargetProperty(translateYAnimation, new PropertyPath(TranslateTransform.YProperty)); this.pathAnimationStoryboard.AutoReverse = true; this.pathAnimationStoryboard.Children.Add(angleAnimation); this.pathAnimationStoryboard.Children.Add(translateXAnimation); this.pathAnimationStoryboard.Children.Add(translateYAnimation); this.BattonPanel.Height = 150.0; this.BattonPanel.Width = 300.0; ImageBrush myBackBrush = new ImageBrush(); myBackBrush.ImageSource = new BitmapImage(new Uri("sampleImages\\back.png", UriKind.Relative)); this.BattonPanel.Background = myBackBrush; TextBlock InfoButtonText = new TextBlock(); InfoButtonText.Text = " НАЗАД"; InfoButtonText.FontFamily = new FontFamily("Arial Black"); InfoButtonText.TextWrapping = TextWrapping.Wrap; //InfoButtonText.BitmapEffect = new BevelBitmapEffect(); InfoButtonText.FontSize = 32.0; this.BattonPanel.MouseDown += new MouseButtonEventHandler(this.InfoCloseButton_Click); }
private void AnimateToRightSheet() { DoubleAnimation translateAnimation = new DoubleAnimation(-Width / 4, new Duration(TimeSpan.FromMilliseconds(500))); BezierSegment bs = new BezierSegment(new Point(0, 1), new Point(1, 0.5), new Point(2, 1), true); PathGeometry path = new PathGeometry(); PathFigure figure = new PathFigure(); figure.StartPoint = new Point(0, 1); figure.Segments.Add(bs); figure.IsClosed = false; path.Figures.Add(figure); DoubleAnimationUsingPath scaleAnimation = new DoubleAnimationUsingPath(); scaleAnimation.PathGeometry = path; scaleAnimation.Source = PathAnimationSource.Y; scaleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); translate.BeginAnimation(TranslateTransform.XProperty, translateAnimation); scale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation); scale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation); }
private void dealcards() { //////////////////////////////////////////////// //////// Deal card 1 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard9 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform", moveCard9); card9.RenderTransform = moveCard9; //create the path PathGeometry animationPath9 = new PathGeometry(); PathFigure pFigure9 = new PathFigure(); pFigure9.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment9 = new PolyBezierSegment(); pBezierSegment9.Points.Add(new Point(30, 350)); pBezierSegment9.Points.Add(new Point(30, 350)); pBezierSegment9.Points.Add(new Point(30, 350)); pFigure9.Segments.Add(pBezierSegment9); animationPath9.Figures.Add(pFigure9); //freeze path for performance benefits animationPath9.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation9 = new DoubleAnimationUsingPath(); translateXAnimation9.PathGeometry = animationPath9; translateXAnimation9.PathGeometry = animationPath9; translateXAnimation9.Duration = TimeSpan.FromSeconds(.5); //set source property to x translateXAnimation9.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation9, "AnimatedTranslateTransform"); Storyboard.SetTargetProperty(translateXAnimation9, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation9 = new DoubleAnimationUsingPath(); translateYAnimation9.PathGeometry = animationPath9; translateYAnimation9.Duration = TimeSpan.FromSeconds(.5); translateYAnimation9.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation9, "AnimatedTranslateTransform"); Storyboard.SetTargetProperty(translateYAnimation9, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation9, "AnimatedTranslateTransform"); Storyboard.SetTargetProperty(translateYAnimation9, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 2 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard8 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform8", moveCard8); card8.RenderTransform = moveCard8; //create the path PathGeometry animationPath8 = new PathGeometry(); PathFigure pFigure8 = new PathFigure(); pFigure8.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment8 = new PolyBezierSegment(); pBezierSegment8.Points.Add(new Point(130, 350)); pBezierSegment8.Points.Add(new Point(130, 350)); pBezierSegment8.Points.Add(new Point(130, 350)); pFigure8.Segments.Add(pBezierSegment8); // animationPath8.Figures.Add(pFigure7); animationPath8.Figures.Add(pFigure8); //freeze path for performance benefits animationPath8.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation8 = new DoubleAnimationUsingPath(); translateXAnimation8.PathGeometry = animationPath8; translateXAnimation8.PathGeometry = animationPath8; translateXAnimation8.Duration = TimeSpan.FromSeconds(.5); //set source property to x translateXAnimation8.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation8, "AnimatedTranslateTransform8"); Storyboard.SetTargetProperty(translateXAnimation8, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation8 = new DoubleAnimationUsingPath(); translateYAnimation8.PathGeometry = animationPath8; translateYAnimation8.Duration = TimeSpan.FromSeconds(.5); translateYAnimation8.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation8, "AnimatedTranslateTransform8"); Storyboard.SetTargetProperty(translateYAnimation8, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation8, "AnimatedTranslateTransform8"); Storyboard.SetTargetProperty(translateYAnimation8, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 3 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard7 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform7", moveCard7); card7.RenderTransform = moveCard7; //create the path PathGeometry animationPath7 = new PathGeometry(); PathFigure pFigure7 = new PathFigure(); pFigure7.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment7 = new PolyBezierSegment(); pBezierSegment7.Points.Add(new Point(710, 350)); pBezierSegment7.Points.Add(new Point(710, 350)); pBezierSegment7.Points.Add(new Point(710, 350)); pFigure7.Segments.Add(pBezierSegment7); animationPath7.Figures.Add(pFigure7); //freeze path for performance benefits animationPath7.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation7 = new DoubleAnimationUsingPath(); translateXAnimation7.PathGeometry = animationPath7; translateXAnimation7.PathGeometry = animationPath7; translateXAnimation7.Duration = TimeSpan.FromSeconds(.7); //set source property to x translateXAnimation7.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation7, "AnimatedTranslateTransform7"); Storyboard.SetTargetProperty(translateXAnimation7, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation7 = new DoubleAnimationUsingPath(); translateYAnimation7.PathGeometry = animationPath7; translateYAnimation7.Duration = TimeSpan.FromSeconds(.7); translateYAnimation7.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation7, "AnimatedTranslateTransform7"); Storyboard.SetTargetProperty(translateYAnimation7, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation7, "AnimatedTranslateTransform7"); Storyboard.SetTargetProperty(translateYAnimation7, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 4 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard6 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform6", moveCard6); card6.RenderTransform = moveCard6; //create the path PathGeometry animationPath6 = new PathGeometry(); PathFigure pFigure6 = new PathFigure(); pFigure6.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment6 = new PolyBezierSegment(); pBezierSegment6.Points.Add(new Point(810, 350)); pBezierSegment6.Points.Add(new Point(810, 350)); pBezierSegment6.Points.Add(new Point(810, 350)); pFigure6.Segments.Add(pBezierSegment6); animationPath6.Figures.Add(pFigure6); //freeze path for performance benefits animationPath6.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation6 = new DoubleAnimationUsingPath(); translateXAnimation6.PathGeometry = animationPath6; translateXAnimation6.PathGeometry = animationPath6; translateXAnimation6.Duration = TimeSpan.FromSeconds(.6); //set source property to x translateXAnimation6.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation6, "AnimatedTranslateTransform6"); Storyboard.SetTargetProperty(translateXAnimation6, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation6 = new DoubleAnimationUsingPath(); translateYAnimation6.PathGeometry = animationPath6; translateYAnimation6.Duration = TimeSpan.FromSeconds(.6); translateYAnimation6.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation6, "AnimatedTranslateTransform6"); Storyboard.SetTargetProperty(translateYAnimation6, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation6, "AnimatedTranslateTransform6"); Storyboard.SetTargetProperty(translateYAnimation6, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 5 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard5 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform5", moveCard5); card5.RenderTransform = moveCard5; //create the path PathGeometry animationPath5 = new PathGeometry(); PathFigure pFigure5 = new PathFigure(); pFigure5.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment5 = new PolyBezierSegment(); pBezierSegment5.Points.Add(new Point(240, -10)); pBezierSegment5.Points.Add(new Point(240, -10)); pBezierSegment5.Points.Add(new Point(240, -10)); pFigure5.Segments.Add(pBezierSegment5); animationPath5.Figures.Add(pFigure5); //freeze path for performance benefits animationPath5.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation5 = new DoubleAnimationUsingPath(); translateXAnimation5.PathGeometry = animationPath5; translateXAnimation5.PathGeometry = animationPath5; translateXAnimation5.Duration = TimeSpan.FromSeconds(.5); //set source property to x translateXAnimation5.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation5, "AnimatedTranslateTransform5"); Storyboard.SetTargetProperty(translateXAnimation5, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation5 = new DoubleAnimationUsingPath(); translateYAnimation5.PathGeometry = animationPath5; translateYAnimation5.Duration = TimeSpan.FromSeconds(.5); translateYAnimation5.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation5, "AnimatedTranslateTransform5"); Storyboard.SetTargetProperty(translateYAnimation5, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation5, "AnimatedTranslateTransform5"); Storyboard.SetTargetProperty(translateYAnimation5, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 6 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard4 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform4", moveCard4); card4.RenderTransform = moveCard4; //create the path PathGeometry animationPath4 = new PathGeometry(); PathFigure pFigure4 = new PathFigure(); pFigure4.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment4 = new PolyBezierSegment(); pBezierSegment4.Points.Add(new Point(340, -10)); pBezierSegment4.Points.Add(new Point(340, -10)); pBezierSegment4.Points.Add(new Point(340, -10)); pFigure4.Segments.Add(pBezierSegment4); animationPath4.Figures.Add(pFigure4); //freeze path for performance benefits animationPath4.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation4 = new DoubleAnimationUsingPath(); translateXAnimation4.PathGeometry = animationPath4; translateXAnimation4.PathGeometry = animationPath4; translateXAnimation4.Duration = TimeSpan.FromSeconds(.4); //set source property to x translateXAnimation4.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation4, "AnimatedTranslateTransform4"); Storyboard.SetTargetProperty(translateXAnimation4, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation4 = new DoubleAnimationUsingPath(); translateYAnimation4.PathGeometry = animationPath4; translateYAnimation4.Duration = TimeSpan.FromSeconds(.4); translateYAnimation4.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation4, "AnimatedTranslateTransform4"); Storyboard.SetTargetProperty(translateYAnimation4, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation4, "AnimatedTranslateTransform4"); Storyboard.SetTargetProperty(translateYAnimation4, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 7 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard3 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform3", moveCard3); card3.RenderTransform = moveCard3; //create the path PathGeometry animationPath3 = new PathGeometry(); PathFigure pFigure3 = new PathFigure(); pFigure3.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment3 = new PolyBezierSegment(); pBezierSegment3.Points.Add(new Point(440, -10)); pBezierSegment3.Points.Add(new Point(440, -10)); pBezierSegment3.Points.Add(new Point(440, -10)); pFigure3.Segments.Add(pBezierSegment3); animationPath3.Figures.Add(pFigure3); //freeze path for performance benefits animationPath3.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation3 = new DoubleAnimationUsingPath(); translateXAnimation3.PathGeometry = animationPath3; translateXAnimation3.PathGeometry = animationPath3; translateXAnimation3.Duration = TimeSpan.FromSeconds(.3); //set source property to x translateXAnimation3.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation3, "AnimatedTranslateTransform3"); Storyboard.SetTargetProperty(translateXAnimation3, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation3 = new DoubleAnimationUsingPath(); translateYAnimation3.PathGeometry = animationPath3; translateYAnimation3.Duration = TimeSpan.FromSeconds(.3); translateYAnimation3.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation3, "AnimatedTranslateTransform3"); Storyboard.SetTargetProperty(translateYAnimation3, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation3, "AnimatedTranslateTransform3"); Storyboard.SetTargetProperty(translateYAnimation3, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 8 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard2 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform2", moveCard2); card2.RenderTransform = moveCard2; //create the path PathGeometry animationPath2 = new PathGeometry(); PathFigure pFigure2 = new PathFigure(); pFigure2.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment2 = new PolyBezierSegment(); pBezierSegment2.Points.Add(new Point(540, -10)); pBezierSegment2.Points.Add(new Point(540, -10)); pBezierSegment2.Points.Add(new Point(540, -10)); pFigure2.Segments.Add(pBezierSegment2); animationPath2.Figures.Add(pFigure2); //freeze path for performance benefits animationPath2.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation2 = new DoubleAnimationUsingPath(); translateXAnimation2.PathGeometry = animationPath2; translateXAnimation2.PathGeometry = animationPath2; translateXAnimation2.Duration = TimeSpan.FromSeconds(.2); //set source property to x translateXAnimation2.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation2, "AnimatedTranslateTransform2"); Storyboard.SetTargetProperty(translateXAnimation2, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation2 = new DoubleAnimationUsingPath(); translateYAnimation2.PathGeometry = animationPath2; translateYAnimation2.Duration = TimeSpan.FromSeconds(.2); translateYAnimation2.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation2, "AnimatedTranslateTransform2"); Storyboard.SetTargetProperty(translateYAnimation2, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation2, "AnimatedTranslateTransform2"); Storyboard.SetTargetProperty(translateYAnimation2, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal card 9 /////////////////////////// //////////////////////////////////////////////// TranslateTransform moveCard1 = new TranslateTransform(); this.RegisterName("AnimatedTranslateTransform1", moveCard1); card1.RenderTransform = moveCard1; //create the path PathGeometry animationPath1 = new PathGeometry(); PathFigure pFigure1 = new PathFigure(); pFigure1.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment1 = new PolyBezierSegment(); pBezierSegment1.Points.Add(new Point(640, -10)); pBezierSegment1.Points.Add(new Point(640, -10)); pBezierSegment1.Points.Add(new Point(640, -10)); pFigure1.Segments.Add(pBezierSegment1); animationPath1.Figures.Add(pFigure1); //freeze path for performance benefits animationPath1.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation1 = new DoubleAnimationUsingPath(); translateXAnimation1.PathGeometry = animationPath1; translateXAnimation1.PathGeometry = animationPath1; translateXAnimation1.Duration = TimeSpan.FromSeconds(.1); //set source property to x translateXAnimation1.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation1, "AnimatedTranslateTransform1"); Storyboard.SetTargetProperty(translateXAnimation1, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation1 = new DoubleAnimationUsingPath(); translateYAnimation1.PathGeometry = animationPath1; translateYAnimation1.Duration = TimeSpan.FromSeconds(.1); translateYAnimation1.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation1, "AnimatedTranslateTransform1"); Storyboard.SetTargetProperty(translateYAnimation1, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard.SetTargetName(translateYAnimation1, "AnimatedTranslateTransform1"); Storyboard.SetTargetProperty(translateYAnimation1, new PropertyPath(TranslateTransform.YProperty)); //////////////////////////////////////////////// //////// Deal the cards /////////////////////////// //////////////////////////////////////////////// Storyboard pathAnimationStoryboard = new Storyboard(); pathAnimationStoryboard.Children.Add(translateXAnimation9); pathAnimationStoryboard.Children.Add(translateYAnimation9); pathAnimationStoryboard.Children.Add(translateXAnimation8); pathAnimationStoryboard.Children.Add(translateYAnimation8); pathAnimationStoryboard.Children.Add(translateXAnimation7); pathAnimationStoryboard.Children.Add(translateYAnimation7); pathAnimationStoryboard.Children.Add(translateXAnimation6); pathAnimationStoryboard.Children.Add(translateYAnimation6); pathAnimationStoryboard.Children.Add(translateXAnimation5); pathAnimationStoryboard.Children.Add(translateYAnimation5); pathAnimationStoryboard.Children.Add(translateXAnimation4); pathAnimationStoryboard.Children.Add(translateYAnimation4); pathAnimationStoryboard.Children.Add(translateXAnimation3); pathAnimationStoryboard.Children.Add(translateYAnimation3); pathAnimationStoryboard.Children.Add(translateXAnimation2); pathAnimationStoryboard.Children.Add(translateYAnimation2); pathAnimationStoryboard.Children.Add(translateXAnimation1); pathAnimationStoryboard.Children.Add(translateYAnimation1); pathAnimationStoryboard.Begin(this); //change the image source of the card. will be used to display actual cards dealt to players/dealer string sUri = @"Images\clubs-2-150.png"; Uri src = new Uri(sUri, UriKind.RelativeOrAbsolute); BitmapImage bmp = new BitmapImage(src); card9.Source = bmp; card8.Source = bmp; card7.Source = bmp; card6.Source = bmp; card5.Source = bmp; card4.Source = bmp; card3.Source = bmp; }
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); }
/* * Animation Helper Methods */ private void moveCard(Image cardImage, int absoluteX, int absoluteY) { string transformName = "theTransform"; int x = absoluteX - (int)cardImage.Margin.Left; int y = absoluteY - (int)cardImage.Margin.Top; if (x != 0 && y != 0) { //create translateTransform TranslateTransform moveCard9 = new TranslateTransform(); this.RegisterName(transformName, moveCard9); cardImage.RenderTransform = moveCard9; //create the path PathGeometry animationPath9 = new PathGeometry(); PathFigure pFigure9 = new PathFigure(); pFigure9.StartPoint = new Point(0, 0); PolyBezierSegment pBezierSegment9 = new PolyBezierSegment(); pBezierSegment9.Points.Add(new Point(x, y)); pBezierSegment9.Points.Add(new Point(x, y)); pBezierSegment9.Points.Add(new Point(x, y)); pFigure9.Segments.Add(pBezierSegment9); animationPath9.Figures.Add(pFigure9); //freeze path for performance benefits animationPath9.Freeze(); //create the animation to move the card horizontally DoubleAnimationUsingPath translateXAnimation9 = new DoubleAnimationUsingPath(); translateXAnimation9.PathGeometry = animationPath9; translateXAnimation9.Duration = TimeSpan.FromSeconds(1); translateXAnimation9.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation9, transformName); Storyboard.SetTargetProperty(translateXAnimation9, new PropertyPath(TranslateTransform.XProperty)); //create the animation to move the card vertically DoubleAnimationUsingPath translateYAnimation9 = new DoubleAnimationUsingPath(); translateYAnimation9.PathGeometry = animationPath9; translateYAnimation9.Duration = TimeSpan.FromSeconds(1); translateYAnimation9.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation9, transformName); Storyboard.SetTargetProperty(translateYAnimation9, new PropertyPath(TranslateTransform.YProperty)); //create a storyboard Storyboard pathAnimationStoryboard = new Storyboard(); pathAnimationStoryboard.Children.Add(translateXAnimation9); pathAnimationStoryboard.Children.Add(translateYAnimation9); //begin the storyboard pathAnimationStoryboard.Begin(this); this.UnregisterName(transformName); } }
/// <summary> /// AGV动画初始化 /// </summary> public void CarAnimationInit() { TranslateTransform translate = new TranslateTransform(); RotateTransform rotate = new RotateTransform(); //AGV标签动画设置 TransformGroup lablegroup = new TransformGroup(); animatedImage.RenderTransformOrigin = new Point(0.5, 0.5); lablegroup.Children.Add(translate);//平移 carLabel.RenderTransform = lablegroup; //AGV图标动画设置 TransformGroup imagegroup = new TransformGroup(); carLabel.RenderTransformOrigin = new Point(0.5, 0.5); imagegroup.Children.Add(rotate);//先旋转 imagegroup.Children.Add(translate);//再平移 animatedImage.RenderTransform = imagegroup; //设置XYAngle关联的动画 animationX = new DoubleAnimationUsingPath(); animationX.Source = PathAnimationSource.X; animationY = new DoubleAnimationUsingPath(); animationY.Source = PathAnimationSource.Y; animationAngle = new DoubleAnimationUsingPath(); animationAngle.Source = PathAnimationSource.Angle; CarFElement.RegisterName("translate" + AnimationNum.ToString(), translate); CarFElement.RegisterName("rotate" + AnimationNum.ToString(), rotate); Storyboard.SetTargetName(animationX, "translate" + AnimationNum.ToString()); Storyboard.SetTargetProperty(animationX, new PropertyPath(TranslateTransform.XProperty)); Storyboard.SetTargetName(animationY, "translate" + AnimationNum.ToString()); Storyboard.SetTargetProperty(animationY, new PropertyPath(TranslateTransform.YProperty)); Storyboard.SetTargetName(animationAngle, "rotate" + (AnimationNum++).ToString()); Storyboard.SetTargetProperty(animationAngle, new PropertyPath(RotateTransform.AngleProperty)); }
/// <summary> /// Play Animation dependence a Button /// </summary> /// <param name="path"></param> /// <param name="empButton"></param> /// <param name="timeSp"></param> public void StartAnimation(Path path, Button empButton, int timeSp) { Storyboard stMain = new Storyboard(); AnimationInfo aniInfo = new AnimationInfo(); aniInfo.EmpName = (string)empButton.ToolTip; aniInfo.SBMain = stMain; aniInfo.UserControlBase = userControlMap; aniInfo.btnEmp = empButton; aniInfo.animaPath = path; aniInfo.CanvasBase = CanvasMap; aniInfo.ViewBoxBase = ViewBoxMap; aniInfo.CanvasRootBase = CanvasRootMap; aniInfo.FollowingEvent += new AnimationInfo.FollowingHandle(aniInfo_FollowingEvent); aniInfo.ReplayEvent += new AnimationInfo.ReplayHandle(aniInfo_ReplayEvent); stMain.Completed += (o, s) => { CanvasMap.Children.Remove(empButton);//移除动画button CanvasMap.Children.Remove(path);//移除path OnFinishedAnimationEvent(string.Format("{0}的轨迹播放完毕!", empButton.ToolTip));//通知播放完毕,没有订阅这个事件则可以不处理 aniInfo.IsFollowing = false;//取消跟踪 aniInfo.IsPaused = true;//暂停,为了重播时直接转成播放风格,而不需要转成暂停再转成播放 aniInfo.Stop(); CheckFinishedAllAnimation(); }; Canvas.SetTop(empButton, -empButton.Height / 2); Canvas.SetLeft(empButton, -empButton.Width / 2); TranslateTransform translate = new TranslateTransform(); ((TransformGroup)empButton.RenderTransform).Children.Add(translate); string RenderName = string.Format("translate{0}", RenderFlag); userControlMap.RegisterName(RenderName, translate); RenderFlag++; DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath(); animationX.PathGeometry = path.Data.GetFlattenedPathGeometry(); animationX.Source = PathAnimationSource.X; animationX.Duration = new Duration(TimeSpan.FromSeconds(timeSp)); DoubleAnimationUsingPath animationY = new DoubleAnimationUsingPath(); animationY.PathGeometry = path.Data.GetFlattenedPathGeometry(); animationY.Source = PathAnimationSource.Y; animationY.Duration = animationX.Duration; Storyboard.SetTargetProperty(animationX, new PropertyPath(TranslateTransform.XProperty)); Storyboard.SetTargetProperty(animationY, new PropertyPath(TranslateTransform.YProperty)); Storyboard.SetTargetName(animationX, RenderName); Storyboard.SetTargetName(animationY, RenderName); stMain.Children.Add(animationX); stMain.Children.Add(animationY); stMain.Begin(userControlMap, true); aniInfo.IsPaused = false; ListStoryboard.Add(stMain); ListButton.Add(empButton); ListPath.Add(path); CollectionAnmInfo.Add(aniInfo); }