Getting Started with .NET MAUI Barcode Generator
8 Jul 20266 minutes to read
This section explains how to add the .NET MAUI Barcode Generator control to your project, set its symbology, and covers the essential features for getting started with the Syncfusion® Barcode Generator control.
To get started quickly with the .NET MAUI Barcode Generator, you can check the following video.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 9 SDK or later.
- Set up a .NET MAUI environment with Visual Studio 2022 v17.12 or later.
- Ensure that the .NET MAUI workloads are installed and configured as described here.
Step 1: Create a new .NET MAUI project
- Go to File > New > Project and choose the .NET MAUI App template.
- Name the project and choose a location. Click Next.
- Select the .NET framework version and click Create.
Step 2: Install the Syncfusion® MAUI Barcode NuGet package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.Barcode and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 9 SDK or later.
- Set up a .NET MAUI environment with Visual Studio Code.
- Ensure that the .NET MAUI workloads are installed and configured as described here.
Step 1: Create a new .NET MAUI project
- Open the Command Palette by pressing Ctrl+Shift+P, type .NET:New Project, and press Enter.
- Choose the .NET MAUI App template.
- Select the project location, type the project name, and press Enter.
- Then choose Create project.
Step 2: Install the Syncfusion® MAUI Barcode NuGet package
- Press Ctrl + ` (backtick) to open the integrated terminal in Visual Studio Code.
- Ensure you’re in the project root directory where your .csproj file is located.
- Run the command
dotnet add package Syncfusion.Maui.Barcodeto install the Syncfusion® .NET MAUI Barcode NuGet package. - To ensure all dependencies are installed, run
dotnet restore.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 9 SDK or later.
- Set up a .NET MAUI environment with JetBrains Rider 2024.3 or later.
- Make sure the MAUI workloads are installed and configured as described here.
Step 1: Create a new .NET MAUI project
- Go to File > New Solution, select .NET (C#), and choose the .NET MAUI App template.
- Enter the Project Name, Solution Name, and Location.
- Select the .NET framework version and click Create.
Step 2: Install the Syncfusion® MAUI Barcode NuGet package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.Barcode and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored. If not, open the Terminal in Rider and manually run:
dotnet restore
Step 3: Register Syncfusion handler
The Syncfusion handler must be registered to enable all Syncfusion MAUI controls in your application. Add the following namespace to your MauiProgram.cs file:
using Syncfusion.Maui.Core.Hosting;Register the Syncfusion core handler in your CreateMauiApp method of MauiProgram.cs file:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}Step 4: Import the Barcode Generator namespace
Add the following namespace in your XAML or C#:
xmlns:barcode="clr-namespace:Syncfusion.Maui.Barcode;assembly=Syncfusion.Maui.Barcode"using Syncfusion.Maui.Barcode;Step 5: Initialize the Barcode Generator
Initialize the SfBarcodeGenerator and set a Value to display the barcode. The following XAML snippet shows how to add a barcode generator in a ContentPage:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:barcode="clr-namespace:Syncfusion.Maui.Barcode;assembly=Syncfusion.Maui.Barcode"
x:Class="BarcodeApp.MainPage">
<barcode:SfBarcodeGenerator Value="12634388927"
HeightRequest="150"
WidthRequest="300">
</barcode:SfBarcodeGenerator>
</ContentPage>SfBarcodeGenerator barcode = new SfBarcodeGenerator()
{
Value = "12634388927",
HeightRequest = 150,
WidthRequest = 300
};
this.Content = barcode;
NOTE
The default symbology of
SfBarcodeGeneratorisCode128. To render other symbologies such asQRCode,DataMatrix, orCodabar, set theSymbologyproperty.
You can download the complete Getting Started sample from GitHub.