public static Path GetParticlePath(Point start, Point end, byte[] rgb, Storyboard sb, PathGeometry geometry, double l) { Path path = new Path { Style = (Style)Application.Current.Resources["ParticlePathStyle"], Data = geometry, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, rgb[0], rgb[1], rgb[2])), OpacityMask = StoryBoard.GetGradientBrush(start, end), }; //path.ToolTip = string.Format("{0}=>{1}",mapitem.ToString(), toItem.To.ToString()); var particleTime = 1 / l; DoubleAnimation pda0 = StoryBoard.Animation3(particleTime); //Path particlePath = PathEllipse.GetParticlePath(startPoint, endPoint, rgb, m_angle, out double l); //particlePath. Storyboard.SetTarget(pda0, path); Storyboard.SetTargetProperty(pda0, new PropertyPath("(Path.OpacityMask).(GradientBrush.GradientStops)[0].(GradientStop.Offset)")); sb.Children.Add(pda0); var pda1 = StoryBoard.Animation3(particleTime); Storyboard.SetTarget(pda1, path); Storyboard.SetTargetProperty(pda1, new PropertyPath("(Path.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Offset)")); sb.Children.Add(pda1); return(path); }
/// <summary> /// 添加控件和动画到容器 /// </summary> /// <param name="item">数据项</param> public static DependencyObject[] GetAnimation(Point startPoint, Point endPoint, double diameter, PathGeometry pathGeometry, byte[] rgb, Storyboard m_Sb, double pointTime, string m_PointData) { //grid_Animation.Children.Clear(); //m_Sb.Children.Clear(); // Random rd = new Random(); // 跑动的点 System.Windows.Controls.Grid grid = GetRunPoint(rgb, m_PointData); //到达城市的圆 Ellipse ell = PathEllipse.GetToEllipse(diameter, diameter, rgb, endPoint); StoryBoard.AddPointToStoryboard(grid, ell, m_Sb, pathGeometry, pointTime); return(new DependencyObject[] { grid, ell }); }