Getting Started with .NET MAUI Barcode Generator

23 Jan 20236 minutes to read

This section explains the steps required to add the .NET MAUI Barcode Generator control. This section explains the steps required to add the barcode and set its symbology. This section covers only basic features needed to get started with Syncfusion barcode generator control.

To get start quickly with our .NET MAUI Barcode Generator, you can check the below video.

Adding a SfBarcodeGenerator reference

The Syncfusion .NET MAUI components are available on nuget.org. To add SfBarcodeGenerator to your project, open the NuGet package manager in Visual Studio, search forĀ [Syncfusion.Maui.Barcode] and then install it.

Register the handler

Syncfusion.Maui.Core nuget is a dependent package for all Syncfusion controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion core.

  • C#
  • using Microsoft.Maui;
    using Microsoft.Maui.Hosting;
    using Microsoft.Maui.Controls.Compatibility;
    using Microsoft.Maui.Controls.Hosting;
    using Microsoft.Maui.Controls.Xaml;
    using Syncfusion.Maui.Core.Hosting;
    
    namespace GaugeMauiSample
    {
        public static class MauiProgram
        {
            public static MauiApp CreateMauiApp()
            {
                var builder = MauiApp.CreateBuilder();
                builder
                .UseMauiApp<App>()
                .ConfigureSyncfusionCore()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });
    
                return builder.Build();
            }
        }
    }

    Adding a namespace

    Add the following namespace to add .NET MAUI Barcode Generator.

    xmlns:barcode="clr-namespace:Syncfusion.Maui.Barcode;assembly=Syncfusion.Maui.Barcode"
    using Syncfusion.Maui.Barcode;

    Initialize the SfBarcodeGenerator control

    <barcode:SfBarcodeGenerator Value="http://www.syncfusion.com" 
                                HeightRequest="150"/>
    SfBarcodeGenerator barcode = new SfBarcodeGenerator();
    barcode.HeightRequest = 150;
    barcode.Value = "http://www.syncfusion.com";
    this.Content = barcode;

    .NET MAUI Barcode Generator Intialize Barcode

    NOTE

    The default symbology of SfBarcodeGenerator is Code128.

    Initialize QR Code symbology

    You can set the required symbology type to the barcode generator based on input value by initializing the Symbology property. In the following code sample, the QR code is set as the barcode symbology.

    <barcode:SfBarcodeGenerator Value="https://www.syncfusion.com/" 
                                        HeightRequest="350" 
                                        WidthRequest="350">
                <barcode:SfBarcodeGenerator.Symbology>
                    <barcode:QRCode />
                </barcode:SfBarcodeGenerator.Symbology>
            </barcode:SfBarcodeGenerator>
    SfBarcodeGenerator barcode = new SfBarcodeGenerator();
    barcode.HeightRequest = 350;
    barcode.WidthRequest = 350;
    barcode.Value = "https://www.syncfusion.com/";
    barcode.Symbology = new QRCode();
    this.Content = barcode;

    .NET MAUI Barcode Generator Intialize QR Code Symbology

    Display input value

    The provided input value can be displayed below the barcode by enabling the ShowText property of barcode as shown in the following code sample.

    <barcode:SfBarcodeGenerator Value="https://www.syncfusion.com/" 
                                        ShowText="True" 
                                        TextSpacing="15" 
                                        HeightRequest="350" 
                                        WidthRequest="350">
                <barcode:SfBarcodeGenerator.Symbology>
                    <barcode:QRCode />
                </barcode:SfBarcodeGenerator.Symbology>
            </barcode:SfBarcodeGenerator>
    SfBarcodeGenerator barcode = new SfBarcodeGenerator();
    barcode.HeightRequest = 350;
    barcode.WidthRequest = 350;
    barcode.Value = "https://www.syncfusion.com/";
    barcode.Symbology = new QRCode();
    barcode.ShowText = true;
    barcode.TextSpacing = 15;
    this.Content = barcode;

    .NET MAUI Barcode Generator Display Input Value

    NOTE

    View sample in GitHub