Updating canvas background color clears drawing

The Problem: Changing the BackgroundColor property of a Canvas element (found under Drawing and Animation) via blocks will clear any drawing you have.

Expected Behavior: The background color of the Canvas should update while the drawing is maintained, not deleted or cleared in any way.

How To Recreate:
Start a new project and insert a Canvas into the screen, make its width to fill the parent and its height 70%. Insert a button afterwards. Program drawing on the canvas in the blocks menu with the Canvas.Dragged event and the Canvas.DrawLine function inside the event.

x1 will be currentX, y1 will be currentY, x2 will be prevX, y2 will be prevY

Program the button to change the BackgroundColor property to a new color when clicked. Run the program and draw on your canvas. When your satisfied with your drawing, press the button to update the background color of the canvas. The background color will update, and your drawing will vanish.

Furthermore: A .aia file (project file) is attached to this post. Inside it is an exact replication of the instructions above, and it demonstrates the bug when tested. I have only seen this bug occur in the Android emulator, but have not tested to see if it occurs on other platforms or not.

CanvasBugDemo.aia (1.8 KB)

It is not ideal, but this is how the canvas drawing tools work, because they are on the same z index as the background colour.

You can work around this by recording the drawing, and then redraw it when you change the background colour

Simple blocks example

3 Likes