2
votes

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

1

1 Answers

4
votes

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.