简体   繁体   English

WPF。 图案 animation class

[英]WPF. Pattern animation class

[I created a DrawingLine animation class to draw patterns. [我创建了一个DrawingLine animation class 来绘制图案。

The constructor starts the process of creating and animating lines:构造函数开始创建和动画线的过程:

internal DrawingLine(double x, double y, int _thickness, Brush _brush, Canvas _canvas)

At the end of the animation, this method generates a new line:在 animation 的末尾,此方法生成一个新行:

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

        }

The method produces animation:该方法产生animation:

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);
        }

Question: What is the best way to loop this animation, so that there are no memory leaks?问题:循环这个 animation 的最佳方法是什么,以便没有 memory 泄漏? I would also like to hear general recommendations for improving the structure of such classes.我还想听听有关改进此类课程结构的一般建议。 Picture of the pattern is attached.] 1附上图案的图片。] 1

I found the answer to my question.我找到了我的问题的答案。 If the class is full of animation, then it supports a recursive call (recursive creation).如果class全是animation,那么它支持递归调用(递归创建)。 A recursive call makes the animation endless.递归调用使 animation 无穷无尽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM