Forum Xamarin Xamarin.Forms

How do i clear the background of signature pad when user changes their sign?

vinothswamivinothswami Member ✭✭✭
edited February 14 in Xamarin.Forms

I saved the signature to the database and retrieve it to the signature pad with the help of background-image property. it is working fine but if a user wants to change the signature he tries to redraw again but the background image is still there which is confusing users.

so how can I remove background signature when a user tries to change their signature.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited February 17

    How did you create the SignaturePad. Try to use the Xamarin.Controls.SignaturePad.Forms plugin which provides the Clear method to clear the signature.

    Page.xaml

    <StackLayout>  
       <forms:SignaturePadView x:Name="MainSignaturePad"  
          BackgroundColor="White"  
          StrokeColor="Black"  
          StrokeWidth="2"  
          WidthRequest="280"  
          HeightRequest="360"/>  
       <Button x:Name="SaveBtn"  
          Text="Save"  
          BackgroundColor="Green"  
          Clicked="SaveBtn_Clicked"/>  
       <Button x:Name="ClearBtn"  
          Text="Clear"  
          BackgroundColor="Red"  
       Clicked="ClearBtn_Clicked"/>  
    </StackLayout>  
    

    Button's click event code:

    private async void SaveBtn_Clicked(object sender, EventArgs e)
    {
        Stream image = await MainSignaturePad.GetImageStreamAsync(SignaturePad.Forms.SignatureImageFormat.Jpeg);
    }
    private void ClearBtn_Clicked(object sender, EventArgs e)
    {
        MainSignaturePad.Clear();
    }
    

    Check the tutoroial:
    https://www.c-sharpcorner.com/article/how-to-create-a-signaturepad-using-xamarin-forms/

Sign In or Register to comment.