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:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio 2022 v17.12 or later.
  3. Ensure that the .NET MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Go to File > New > Project and choose the .NET MAUI App template.
  2. Name the project and choose a location. Click Next.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI Barcode NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.Barcode and install the latest version.
  3. Ensure the necessary dependencies are installed correctly, and the project is restored.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio Code.
  3. Ensure that the .NET MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Open the Command Palette by pressing Ctrl+Shift+P, type .NET:New Project, and press Enter.
  2. Choose the .NET MAUI App template.
  3. Select the project location, type the project name, and press Enter.
  4. Then choose Create project.

Step 2: Install the Syncfusion® MAUI Barcode NuGet package

  1. Press Ctrl + ` (backtick) to open the integrated terminal in Visual Studio Code.
  2. Ensure you’re in the project root directory where your .csproj file is located.
  3. Run the command dotnet add package Syncfusion.Maui.Barcode to install the Syncfusion® .NET MAUI Barcode NuGet package.
  4. To ensure all dependencies are installed, run dotnet restore.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with JetBrains Rider 2024.3 or later.
  3. Make sure the MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Go to File > New Solution, select .NET (C#), and choose the .NET MAUI App template.
  2. Enter the Project Name, Solution Name, and Location.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI Barcode NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.Barcode and install the latest version.
  3. 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;

.NET MAUI Barcode Generator Initialize Barcode

NOTE

The default symbology of SfBarcodeGenerator is Code128. To render other symbologies such as QRCode, DataMatrix, or Codabar, set the Symbology property.

You can download the complete Getting Started sample from GitHub.