Reputation: 21
I'm new to Xamarin. I want to implent a signature pad when the user clicks a button and save the signature to a variable. I want to use this signature pad https://components.xamarin.com/view/signature-pad and I tried to implement the pad as described.
I dont get any errors, but my problem is, that the signature pad appears and I can do the signature and then i can't save the signature, because there's no button. If I click the "back" button of the android phone, the activity which called the signature pad is closed.
Picture on Android phone: no save button
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uri = Android.Net.Uri;
using Environment = Android.OS.Environment;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Provider;
using Android.Content.PM;
using Xamarin.Forms;
using Java.IO;
using SignaturePad;
namespace iSTA
{
[Activity(Label = "Zähler Einbau")]
public class ZEinbau : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.ZEinbau);
Android.Graphics.Bitmap unterschrift;
//some other code
//Button Unterschrift
Android.Widget.Button btnUnterschrift = FindViewById<Android.Widget.Button>(Resource.Id.btnUnterschrift);
btnUnterschrift.Click += delegate
{
SignaturePadView sp = new SignaturePadView(this);
AddContentView(sp, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
unterschrift = sp.GetImage(); ;
};
//some other code
}
}
Upvotes: 2
Views: 2516
Reputation: 11787
It does not come with a SAVE or OK button. It only has the signature pad. You can add your own buttons - save, ok, cancel, etc.
For saving, you can save the signature as image or points array.
as image :
var image = signature.GetImage();
as points array :
// Discontinuous lines are separated by PointF.Empty
PointF[] points = signature.Points;
Useful links :
Getting started - https://components.xamarin.com/gettingstarted/signature-pad
Sample Xamarin forms app - https://github.com/xamarin/SignaturePad/tree/master/samples/Sample.Forms
Sample android App - https://github.com/xamarin/SignaturePad/tree/master/samples/Sample.Android
Upvotes: 3
Reputation: 4032
If you are using Xamarin.Forms you can use the example I have provided on this Github repository:
https://github.com/15mgm15/Xamarin-Forms-Signature
This example shows you how to save a signature pad without using any component.
Hope this helps.
Upvotes: 3