.NET MAUI - Issue with Gestures while Canvas is Invalidated

Sebastien Guienne 5 Reputation points
2023-12-24T16:42:32.3533333+00:00

In a basic .NET MAUI application, when a user tries to perform a gesture on a page containing a GraphicsView while the canvas is (re)drawn leads to a "unmanaged exception". After several attempts to identify the source of the problem, the following steps were taken to reproduce the issue (tested only on Win 11):

  1. Create a basic page and add any implementation of GraphicsView with any IDrawable that implements the "Draw" method (for example, canvas.DrawImage(...) with a MemoryStream).
  2. Trigger the "Draw" method by calling Invalidate() on the view to force a refresh. This can be done through a timer or any other method.
  3. Then, perform a gesture on the screen (drag, drop, pan, etc.) even if there is no event handled.
  4. It seems that if the "Invalidate()" causing refresh occurs While the gesture, the app crashes.

Another way to get the same issue is to react on PanGestureRecognizer_PanUpdated, when GestureStatus.Running and call Invalidate() to refresh the canvas. It seems this issue occurs when the "Invalidate()" causing a refresh occurs while a gesture is being performed

This randomly leads to a "Win32 non managed exception." It is believed that this is because the component is "reset" during the Invalidate() on a start/stop interaction. This is a real problem if the view needs to be refreshed because the user is actually drawing on it.

Can anyone provide help with this issue? Is there a way to refresh the canvas content while actually drawing on it ?

Any sample for a basic "paint" app ?

Thanks in advance for any explanation.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,830 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.