Maui: [BUG] DrawingView Doesn't Clear Lines When Navigating Back to Screen B
Is there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
I am facing an issue with the DrawingView in the MAUI Community Toolkit. The problem occurs when navigating between two screens (A and B) in my app.
Actual Behavior: The line/signature drawn on the DrawingView remains visible even after navigating away and coming back, despite attempting to clear the drawing.
Expected Behavior
When the user navigates back to Screen A and then returns to Screen B, the DrawingView should be cleared, showing a blank canvas.
Steps To Reproduce
Launch the app, which starts on Screen A. On Screen A, there is a “Go” button. When the user clicks this button, the app navigates to Screen B. On Screen B, the user draws a signature or line using the DrawingView. The user then navigates back to Screen A. Upon clicking the “Go” button again to navigate to Screen B, the previously drawn line/signature is still visible, even though I have attempted to clear the DrawingView when navigating back.
Link to public reproduction project repository
https://github.com/jamesmontemagno/MauiSignaturePad
Environment
- .NET MAUI CommunityToolkit:
- OS:
- .NET MAUI:
Anything else?
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 22 (9 by maintainers)
@LaBoss thanks for the pointer. It does sound like there is a potential issue around navigating away from a page and back to the same instance with a DrawingView and things appear disconnected.
As a workaround you can avoid navigating back to the same instance and try to use a new instance of the page each time. That is what our sample application does and that is how I have been able to get your repo working. I made the following changes:
AppShell.xaml
Remove the
MainPageentry so it should look as follows:MauiProgram.cs
Register a route to the
MainPage->Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));.This will result in your
MauiProgramfile looking as follows:testview.xaml.cs
Change the query when navigating to
MainPage.I don’t have, i think the problem is on OnDrawingViewUnloaded all handler’s are removed and then when you return to the page they are not added again