Stoyan,
We're getting some interesting results with this code ~ the links appear to animate in straight lines (between the start point and end point of a link) instead of along the segments. I've tried to create a PointAnimationUsingKeyFrames animation with a EasingPointKeyFrames containing the control points and estimated key times (based on the length of the link as a whole). Unfortunately, we get the same sort of results, only this time applied to the initial segment (as opposed to previously, where the entire linke was fllipped).
Here's the code I'm using:
public const delayConst = 1;
public void Animate(Point from, Point to)
{
var animation = new PointAnimationUsingKeyFrames();
double lineLength = 0;
int segmentCount = this.link.ControlPoints.Count;
List<KeyValuePair<double, Point>> segmentArray = new List<KeyValuePair<double, Point>>();
for (int x = 0; x < segmentCount; x++)
{
double xVal = 0;
double yVal = 0;
if (x == segmentCount  1)
{
xVal = link.ControlPoints[x].X  link.EndPoint.X;
yVal = link.ControlPoints[x].Y  link.EndPoint.Y;
}
else
{
xVal = link.ControlPoints[x].X  link.ControlPoints[x + 1].X;
yVal = link.ControlPoints[x].Y  link.ControlPoints[x + 1].Y;
}
double xValSquared = Math.Pow(xVal, 2);
double yValSquared = Math.Pow(yVal, 2);
double segmentLength = Math.Sqrt(xValSquared + yValSquared);
segmentArray.Add(new KeyValuePair<double, Point>(segmentLength, link.ControlPoints[x]));
lineLength += segmentLength;
}
int delayConstInMilli = delayConst * 1000;
foreach (KeyValuePair<double,Point> pair in segmentArray)
{
EasingPointKeyFrame frame = new EasingPointKeyFrame()
{
KeyTime = new TimeSpan(0, 0, 0, 0, (int)Math.Ceiling((pair.Key * delayConstInMilli) / lineLength)),
Value = pair.Value
};
animation.KeyFrames.Add(frame);
}
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
Storyboard.SetTarget(animation, this);
Storyboard.SetTargetProperty(animation, new PropertyPath(PointProperty));
storyboard.Begin(); }
All help much appreciated,
Mark Goolara, LLC
