This tutorial shows how to use the LEADTOOLS SDK in a C# Xamarin application and create a project, add references, and set a license.
Xamarin Framework Deprecation
As of LEADTOOLS v23, The cross-platform Xamarin framework has been deprecated and replaced with LEADTOOLS .NET MAUI framework.
For any LEADTOOLS Xamarin apps you have already built, we recommend you migrate to the LEADTOOLS .NET MAUI framework. To help you with the migration, review the LEADTOOLS .NET MAUI tutorials to get you started.
This change is driven by Microsoft's announcement to end Xamarin support.
Overview | |
---|---|
Summary | This tutorial covers how to set a license in a C# Xamarin application |
Completion Time | 30 minutes |
Visual Studio Project | Download tutorial project (458 KB) |
Platform | C# Xamarin Cross-Platform Application |
IDE | Visual Studio 2017, 2019, 2022 |
Development License | Download LEADTOOLS |
Try it in another language |
|
Before any functionality from the SDK can be leveraged, a valid runtime license will have to be set.
For instructions on how to obtain a runtime license refer to Obtaining a License.
Launch Visual Studio and select Create a new project.
Select Mobile App (Xamarin.Forms) and click Next.
Add the project name, specify the location where the project to be saved to and the other project details, then click Create.
Select the desired template and the platforms for the project and then click OK.
Add the necessary LEADTOOLS references. The references needed depend upon the purpose of the project. References will be added via NuGet reference:
Right-click the C# project in the Solution Explorer and select Manage NuGet Packages...
Browse for LEADTOOLS, then select one of the LEADTOOLS NuGet packages (any one will do) and install it. Accept LEAD's End User License Agreement.
Note
Your NuGet package manager & package versions may differ.
Now that the LEADTOOLS references have been added to the project, code can be added to set the runtime license. The License unlocks the features needed for the project. It must be set before any toolkit function is called. The exact function called depends on the platform used. For details (including tutorials for different platforms), refer to Setting a Runtime License.
There are two types of runtime licenses:
Perform the following steps to add the SetLicense()
code:
In the Solution Explorer, open MainPage.xaml.cs
to bring up the code behind the MainPage
. Add a using Leadtools;
to the using
block at the top.
In the MainPage()
method add the below code before InitializeComponent()
.
public MainPage()
{
#if __IOS__
Leadtools.Converters.Assembly.Use();
#endif
Leadtools.Core.Assembly.Use();
Leadtools.Svg.Assembly.Use();
Leadtools.Platform.RuntimePlatform = Device.RuntimePlatform;
RasterSupport.Initialize(this);
// TODO: Add your license information
string licString = "[License]\n" + "License = <doc><ver>2.0</ver>``PASTE YOUR LICENSE CONTENTS HERE``</doc>";
string developerKey = "PASTE YOUR DEVELOPER KEY HERE";
byte[] licBytes = Encoding.UTF8.GetBytes(licString);
RasterSupport.SetLicense(licBytes, developerKey);
if (RasterSupport.KernelExpired)
DisplayAlert("Error", "License file invalid or expired.", "OK");
else
DisplayAlert("Success", "License file set successfully!", "OK");
InitializeComponent();
}
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, a message on the device will appear displaying License file set successfully!
Inside Visual Studio for Mac, select the device to deploy to and press the "play" button.
If the steps were followed correctly, a message on the device will appear displaying License file set successfully!
This tutorial showed how to create a new C# Xamarin.Forms Project, add references via NuGets, and set the LEADTOOLS license.
This is the basis for all C# Xamarin applications using the LEADTOOLS SDK. All functionality in the SDK is unlocked via setting a license. SetLicense
must be called before calling any other LEADTOOLS SDK functions.
After the SDK is purchased, the evaluation license can be replaced with a valid runtime license to disable the Nag Message.