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?

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)

Most upvoted comments

@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 MainPage entry so it should look as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="MauiDrawing.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MauiDrawing"
    Shell.FlyoutBehavior="Disabled"
    Title="MauiDrawing">

    <ShellContent
        Title="Test"
        ContentTemplate="{DataTemplate local:testview}"
        Route="testview" />
     

</Shell>

MauiProgram.cs

Register a route to the MainPage -> Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));.

This will result in your MauiProgram file looking as follows:

using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;

namespace MauiDrawing;
public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder.UseMauiApp<App>().ConfigureFonts(fonts =>
        {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
        }).UseMauiCommunityToolkit();
#if DEBUG
        builder.Logging.AddDebug();
#endif
        
        Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
        
        return builder.Build();
    }
}

testview.xaml.cs

Change the query when navigating to MainPage.

namespace MauiDrawing;

public partial class testview : ContentPage
{
	public testview()
	{
		InitializeComponent();
	}

    void Button_Clicked(System.Object sender, System.EventArgs e)
    {
         Shell.Current.GoToAsync($"{nameof(MainPage)}");
    }
}

@LaBoss do have any workaround? I am facing this issue on Android only iOS its Working Fine .

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