如何以编程方式为路径设置动画 [英] how to animate path programmatically
问题描述
我有一个x,y坐标列表?
i have a list of coordinate of x, y?
我不知道M代表什么吗?
i do not know M stand for?
我猜是M,x,y
但无法将字符串传递给animationPath.Figures,我看到xaml是字符串
but can not pass string to animationPath.Figures, i see that xaml it is a string
PathGeometry animationPath = new PathGeometry();
//PathFigure pFigure = new PathFigure();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine(@"
M, 0.9635179096, 0.2676438638,
M, 0.9563515710, 0.2922185356,
M, 0.9486832981, 0.3162277660,
M, 0.9405538997, 0.3396444638,
M, 0.9320046715, 0.3624462612,
M, 0.9230769231, 0.3846153846,
M, 0.9138115486, 0.4061384660,
M, 0.9042486468, 0.4270063054,
M, 0.8944271910, 0.4472135955,
M, 0.8843847528, 0.4667586196,
M, 0.8741572761, 0.4856429312,
M, 0.8637789009, 0.5038710255,
M, 0.8532818337, 0.5214500094,
M, 0.8426962598, 0.5383892771,
M, 0.8320502943, 0.5547001962,
M, 0.8213699657, 0.5703958095,
M, -0.8106792284, -0.5854905538,
M, -0.8000000000, -0.6000000000,
M, -0.7893522174, -0.6139406135,
M, -0.7787539091, -0.6273295379,
M, -0.7682212796, -0.6401843996,
M, -0.7577688024, -0.6525231354,
M, -0.7474093187, -0.6643638388,
M, -0.7371541402, -0.6757246285,
M, -0.7270131526, -0.6866235329,
M, -0.7169949188, -0.6970783933,
M, -0.7071067812, -0.7071067812,
M, -0.6973549597, -0.7167259310,
M, -0.6877446478, -0.7259526841,
M, -0.6782801028, -0.7348034445,
M, -0.6689647317, -0.7432941462,
M, -0.6598011732, -0.7514402251,
M, -0.6507913733, -0.7592566025,
M, -0.6419366566, -0.7667576729,
M, -0.6332377903, -0.7739572991,
M, -0.6246950476, -0.7808688094,
M, -0.6163082616, -0.7875050011,
M, -0.6080768777, -0.7938781461,
M, -0.6000000001, -0.7999999999,
M, -0.5920764340, -0.8058818129,
M, -0.5843047258, -0.8115343415,
M, -0.5766831975, -0.8169678633,
M, -0.5692099789, -0.8221921916,
M, -0.5618830356, -0.8272166912,
M, -0.5547001962, -0.8320502943,
M, -0.5476591746, -0.8367015169,
M, -0.5407575912, -0.8411784754,
M, -0.5339929915, -0.8454889030,
M, -0.5273628618, -0.8496401662,
M, -0.5208646456, -0.8536392804,
M, -0.5144957554, -0.8574929258,
M, -0.5082535846, -0.8612074626,
M, -0.5021355174, -0.8647889466,
M, -0.4961389384, -0.8682431421,
M, -0.4902612396, -0.8715755372,
M, -0.4844998279, -0.8747913561,
M, -0.4788521307, -0.8778955729,
M, -0.4733156006, -0.8808929233,
M, -0.4678877204, -0.8837879164,
M, -0.4625660066, -0.8865848462,
M, -0.4573480127, -0.8892878023,
M, -0.4522313309, -0.8919006802,
M, -0.4472135955, -0.8944271910,
M, -0.4422924841, -0.8968708706,
M, -0.4374657188, -0.8992350888,
M, -0.4327310676, -0.9015230574,
M, -0.4280863448, -0.9037378389,
M, -0.4235294117, -0.9058823529,
M, -0.4190581774, -0.9079593845,
M, -0.4146705982, -0.9099715902,
M, -0.4103646774, -0.9119215052,
M, -0.4061384661, -0.9138115486,
M, -0.4019900620, -0.9156440302");
animationPath.Figures = sb.ToString();
DoubleAnimationUsingPath pathAnimation1 = new DoubleAnimationUsingPath();
pathAnimation1.PathGeometry = animationPath;
Storyboard s = new Storyboard();
//s.Children.Add(widthAnimation1);
//s.Children.Add(heightAnimation1);
//s.Children.Add(marginAnimation);
s.RepeatBehavior = RepeatBehavior.Forever;
s.Duration = new Duration(TimeSpan.FromSeconds(2));
新建
推荐答案
PathGeometry的Figures属性类型为PathFigureCollection,因此只能设置为PathFigureCollection. XAML解析器基于字符串为您创建PathFigureCollection.您可以使用PathFigureCollection.Parse进行相同的操作 方法:
The Figures property of an PathGeometry is of type PathFigureCollection and can thus only be set to a PathFigureCollection. The XAML parser creates a PathFigureCollection for you based on a string. You can do the same using the PathFigureCollection.Parse method:
animationPath.Figures = PathFigureCollection.Parse(sb.ToString());
您的格式无效.这些点应仅以空格分隔,坐标应以逗号分隔,例如:
Your format is invalid though. The points should be separated by only a space and the coordinates by a comma, e.g:
sb.AppendLine(@"
M 0.9635179096, 0.2676438638
M 0.9563515710, 0.2922185356
M 0.9486832981, 0.3162277660
M 0.9405538997, 0.3396444638
M 0.9320046715, 0.3624462612
M 0.9230769231, 0.3846153846
M 0.9138115486, 0.4061384660
M 0.9042486468, 0.4270063054
M 0.8944271910, 0.4472135955
M 0.8843847528, 0.4667586196");
>>我不知道M代表什么?
大写字母M表示新当前点的绝对位置.请参考MSDN以获取更多信息: https://msdn.microsoft.com/en-us/library/ms747393 (v = vs.110).aspx
The capital M indicates an absolute location for the new current point. Please refer to MSDN for more information: https://msdn.microsoft.com/en-us/library/ms747393(v=vs.110).aspx
希望有帮助.
请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于如何以编程方式为路径设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!