0

my question is related to https://stackoverflow.com/a/51388226. How to draw and animate multiple RectangleGeometry.Rect in WPF/C#.

The task of the program is to shortly visualize points on a map.

I have created an array of points. At these points, rectangles should be displayed on the canvas and resized by an animation. Once the animation is completed, I would like to remove the rectangles.

At the moment the rectangles are drawn and animated. However, the animation stops and the rectangles are not removed.

I am not sure if I need "storyboards" for this project and I don't know the concept behind it yet. But would be grateful for any help.

FireAndDeleteAnimation(StartArray)

public void FireAndDeleteAnimation(Point[] StartArray)
        {

            foreach(Point item in StartArray)
            {
                var myRectangleGeometry = new RectangleGeometry(
                new Rect(item.X, item.Y, 200, 200));

                var myPath = new Path
                {
                    Fill = Brushes.Green,
                    StrokeThickness = 1,
                    Stroke = Brushes.Black,
                    Data = myRectangleGeometry
                };

                var myRectAnimation = new RectAnimation
                {
                    Duration = TimeSpan.FromSeconds(2),
                    FillBehavior = FillBehavior.HoldEnd,
                    From = new Rect(item.X - 100, item.Y - 100, 200, 200),
                    To = new Rect(item.X - 5, item.Y - 5, 10, 10)
                };
                
                myRectangleGeometry.BeginAnimation(RectangleGeometry.RectProperty, myRectAnimation);
                ConfigArea.Children.Add(myPath);

                //This is not working:
                myRectAnimation.Completed += (s, e) => ConfigArea.Children.Remove(myPath);

            }
        }

0 Answers0