2

I have a signature pad in my xamarin forms app. User sign on the signature pad and moves to the next screen. But when user come back on signature pad screen, the previous signature gets remove from signature pad. How I can set that the signature should not delete until user do at current state of app?

I save the signature value as byte array when user moves to next screen. So can I bind this byte array at signature pad to show the signature?

Regards, Anand Dubey

anand
  • 1,399
  • 5
  • 23
  • 55

1 Answers1

4

Since this is Xamarin Forms, I'm assuming you're using Allan Ritchie's Acr.XamForms.SignaturePad classes.

The SignaturePadView class exposes a method: LoadDrawPoints, that allows you to load the signature data into the view. Since this is a method, you can't really databind to it, but you can add code to the hosting view to load the signature:

// NOTE: The below assumes that
// A) You're using MVVM (as you should :) )
// B) The ViewModel class name is MyViewModelClassName (change appropriately)
// C) The property on the VM that exposes the signature points is named SignaturePoints (change appropriately)

protected override OnAppearing() {
  LoadSignature();
}

protected override OnBindingContextChanged() {
  LoadSignature();
}

private void LoadSignature() {
    var vm = this.BindingContext as MyViewModelClassName;
    if (vm != null && vm.SignaturePoints != null) {
      this.signaturePadView.LoadDrawPoints(vm.SignaturePoints);
    }
}

Lastly, you mention that you're saving the signature as a byte array; the above code assumes that it's an array of DrawPoint, which is a pair of floats, so you'd need to reverse whatever conversion you're currently doing.

haldo
  • 14,512
  • 5
  • 46
  • 52
Andy Hopper
  • 3,618
  • 1
  • 20
  • 26
  • Thank you so much Andy... It worked. One more problem I need to ask, that there are multiple controls on the screen where signature pad is placed. So the screen gets scrollable. When I try to sign on signature pad the screen start to scrolling. How I can stop the scrolling of screen if user is signing on signature pad? – anand Jul 07 '16 at 11:47
  • Hi Andy, Do you know how I can get the touch event of signature pad or how focused event work in signature pad? I am trying to get touch event so that I can disable the scrollview when user touch the signature pad. But I am not getting any event that can work. Please update if you know how I can get touch event for signature pad? – anand Jul 08 '16 at 10:19
  • I'm afraid I'm not up on the internals of the SignaturePad. I'm sure there's a way, but it may require that you extend the XamForms view to support it. A simpler approach may be to have a dedicated view for the signature (hence no need for scrolling) and pushing that on to the navigation stack. – Andy Hopper Jul 08 '16 at 15:30
  • I have an image how do i load the image in Singature Pad. there is no way to get Drawpoints array of that image. However that image was created using signature pad. – Rusty May 08 '17 at 07:12