【发布时间】:2020-05-08 12:00:50
【问题描述】:
[我创建了一个DrawingLine 动画类来绘制图案。
构造函数开始创建和动画线的过程:
internal DrawingLine(double x, double y, int _thickness, Brush _brush, Canvas _canvas)
在动画结束时,该方法生成一个新行:
void CreateNewLine(object sender, EventArgs e)
{
Line newLine = new Line();
switch (lines.Count % 2 == 0)
{
case true:
{
if (lines.Count < 18)
{
newLine.X1 = 0;
newLine.Y1 = 180 - offset;
newLine.X2 = 0;
newLine.Y2 = 180 - offset;
}
// ... <-- Here is the math determines the positions of the points of the line
}
该方法产生动画:
void AnimateXY()
{
DoubleAnimation lineXAnimation = new DoubleAnimation();
lineXAnimation.From = CurrentLine.X1;
lineXAnimation.To = to_X;
lineXAnimation.Duration = TimeSpan.FromSeconds(duration);
DoubleAnimation lineYAnimation = new DoubleAnimation();
lineYAnimation.From = CurrentLine.Y1;
lineYAnimation.To = to_Y;
lineYAnimation.Duration = TimeSpan.FromSeconds(duration);
lineYAnimation.Completed += CreateNewLine;
CurrentLine.BeginAnimation(Line.X2Property, lineXAnimation);
CurrentLine.BeginAnimation(Line.Y2Property, lineYAnimation);
}
问题:循环这个动画的最佳方法是什么,这样就不会出现内存泄漏?我还想听听有关改进此类课程结构的一般建议。附上图案图片。]1
【问题讨论】:
标签: wpf loops animation design-patterns usability