Step 2
Now, a new window will open on your screen. Select, Blank App under template, select the platforms .i.e., on which platforms you want to deploy your application. Then, select .NET Standard and click OK.
Step 3
Now, in Solution Explorer, select Portable Class File as a Startup Project.
Step 4
Now, in select explorer, under Portable Class, click on "Manage NuGet Packages".
Step 5
Now, in NuGet Package Manager, browse for Xamarin.Controls.SignaturePad.Forms and install the package.
Step 6
Now, open the MainPage.xaml file and the following namespace in it.
XAML Namespace
- xmlns:forms="clr-namespace:SignaturePad.Forms;assembly=SignaturePad.Forms"
Now, write the following XAML code in it.
In the above code, we have declared StackLayout because we want our UI Design in the form of Stack. Then, we are using SignaturePad View in our application. StrokeWidth indicates the width of the stroke, i.e., when you use the SignaturePad. The width of your signature is set to 2. StrokeColor indicates the color of your stroke, i.e., black, green, yellow,... WidthRequest is used to set the width of your SignaturePad and similarly, we use HeightRequest to set the height of your SignaturePad. Then, we create two buttons one for saving your signature and another one for erasing/undo your signature.
Step 7
Now, open your MainPage.xaml.cs File and write the following code in it. For using the functions of SignaturePad use System.IO.
C# 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();
- }
In SaveBtn you can format the type of the image in it like .jpeg,.png,.jpg.
Step 8
Now, build your application and then deploy it.
Now, we have successfully developed a SignaturePad application in Xamarin.Forms.