Migrate from Xamarin.Forms SfBarcode to .NET MAUI SfBarcodeGenerator

28 Apr 20228 minutes to read

To make the migration from the Xamarin SfBarcode to .NET MAUI SfBarcodeGenerator easier, most of the APIs from the Xamarin SfBarcode were kept in the.NET MAUI SfBarcodeGenerator. However, to maintain the consistency of API naming in the .NET MAUI SfBarcodeGenerator, some of the APIs have been renamed. Please find the difference in the following topics.

Initialize control

To initialize the control, import the Barcode namespace and initialize SfBarcodeGenerator as shown in the following code sample.

Xamarin SfBarcode .NET MAUI SfBarcodeGenerator
<ContentPage
    xmlns:syncfusion="clr-namespace:Syncfusion.SfBarcode.XForms;assembly=Syncfusion.SfBarcode.XForms">

        <syncfusion:SfBarcode/>

</ContentPage>
using Syncfusion.SfBarcode.XForms;
...

SfBarcode barcode = new SfBarcode();
...
<ContentPage
    xmlns:barcode="clr-namespace:Syncfusion.Maui.Barcode;assembly=Syncfusion.Maui.Barcode">

        <barcode:SfBarcodeGenerator/>

</ContentPage>
using Syncfusion.Maui.Barcode;
...

SfBarcodeGenerator barcode = new SfBarcodeGenerator();
...

Initialize Symbology

Xamarin SfBarcode .NET MAUI SfBarcodeGenerator Description

CodaBarSettings

Codabar

It is used to configure the Codabar barcode.

Code39Settings

Code39

It is used to configure the Code39 barcode.

Code39ExtendedSettings

Code39Extended

It is used to configure the Code39Extended barcode.

Code93Settings

Code93

It is used to configure the Code93 barcode.

Code128ASettings

Code128A

It is used to configure the Code128A barcode.

Code128BSettings

Code128B

It is used to configure the Code128B barcode.

Code128CSettings

Code128C

It is used to configure the Code128C barcode.

QRBarcodeSettings

QRCode

It is used to configure the QRCode barcode.

DataMatrixEncoding

DataMatrix

It is used to configure the DataMatrix barcode.

The following code example, explains how to initialize symbology and customize symbology settings in Xamarin SfBarcode and .NET MAUI SfBarcodeGenerator.

Xamarin SfBarcode .NET MAUI SfBarcodeGenerator
<syncfusion:SfBarcode Text="http://www.syncfusion.com"
                      BackgroundColor="Gray"
                      Symbology="QRCode">
    <syncfusion:SfBarcode.SymbologySettings>
        <syncfusion:QRBarcodeSettings XDimension="6" 
                                      ErrorCorrectionLevel="High"
                                      InputMode="BinaryMode" 
                                      Version="VersionAuto"/>
    </syncfusion:SfBarcode.SymbologySettings>
</syncfusion:SfBarcode>
SfBarcode barcode = new SfBarcode();
barcode.BackgroundColor = Color.Gray;
barcode.Text = "http://www.syncfusion.com";
barcode.Symbology = BarcodeSymbolType.QRCode;
QRBarcodeSettings settings = new QRBarcodeSettings();
settings.XDimension = 6;
settings.ErrorCorrectionLevel = ErrorCorrectionLevel.High;
settings.InputMode = InputMode.BinaryMode;
settings.Version = QRVersion.VersionAuto;
barcode.SymbologySettings = settings;
this.Content = barcode;
<barcode:SfBarcodeGenerator Value="http://www.syncfusion.com"
                            ShowText="True"
                            BackgroundColor="Gray">
    <barcode:SfBarcodeGenerator.Symbology>
        <barcode:QRCode Module="2"
                        ErrorCorrectionLevel="High"
                        InputMode="Binary" 
                        CodeVersion="Auto"/>
    </barcode:SfBarcodeGenerator.Symbology>
</barcode:SfBarcodeGenerator>
SfBarcodeGenerator barcode = new SfBarcodeGenerator();
 barcode.Value = "http://www.syncfusion.com";
 barcode.BackgroundColor = Colors.Gray;
 barcode.ShowText = true;
 barcode.Symbology = new QRCode() 
 { 
   Module = 2,
   InputMode = QRInputMode.Binary,
   ErrorCorrectionLevel = ErrorCorrectionLevel.High,
   CodeVersion = QRCodeVersion.Auto, 
 };
 this.Content = barcode;

Properties

Xamarin SfBarcode .NET MAUI SfBarcodeGenerator Description

Text

Value

Gets or sets the value of the SfBarcodeGenerator to be rendered, which is displayed below the Barcode element when the ShowText property is enabled.

TextGapHeight

TextSpacing

Gets or sets a value to specify the space between the text and the barcode.

DarkBarColor

ForegroundColor

Gets or sets the value that represents the color of barcode elements.

LightBarColor

BackgroundColor Gets or sets the value that represents the background color of barcode elements.

Version

CodeVersion

Gets or sets a value to define the version that is used to encode the amount of data.

Barcode customization

The following code example explains how to customize barcode and text in Xamarin SfBarcode and .NET MAUI SfBarcodeGenerator.

In .NET MAUI SfBarcodeGenerator, text customization is achieved by using the TextStyle property of the barcode generator as follows.

Xamarin SfBarcode .NET MAUI SfBarcodeGenerator
<syncfusion:SfBarcode Text="123456789" 
                       Symbology="Code128A"
                       TextColor="Red"
                       TextFont="16"
                       TextGapHeight="25"
                       TextLocation="Bottom"
                       TextAlignment="Center">
 </syncfusion:SfBarcode>
SfBarcode barcode = new SfBarcode(); 
barcode.Text = "123456789"; 
barcode.Symbology = BarcodeSymbolType.Code128A;
barcode.TextColor = Color.Red;
barcode.TextFont = Font.SystemFontOfSize(16);
Typeface textStyle = Typeface.create("Times new roman",1); 
barcode.TextFont = textStyle**;** 
barcode.TextGapHeight = 25;
barcode.TextLocation = BarcodeTextLocation.Bottom;
barcode.TextAlignment = BarcodeTextAlignment.Center;
this.Content = barcode;
<barcode:SfBarcodeGenerator Value="123456789"
                            TextSpacing="25"
                            TextAlignment="Center">
    <barcode:SfBarcodeGenerator.Symbology>
        <barcode:Code128A Module="2"/>
    </barcode:SfBarcodeGenerator.Symbology>
    <barcode:SfBarcodeGenerator.TextStyle>
        <barcode:BarcodeTextStyle FontSize="16"
                                  TextColor="Red"/>
    </barcode:SfBarcodeGenerator.TextStyle>
</barcode:SfBarcodeGenerator>
SfBarcodeGenerator barcode = new SfBarcodeGenerator();
barcode.Value = "123456789";
barcode.TextAlignment = TextAlignment.End;
barcode.TextSpacing = 25;
barcode.TextStyle = new BarcodeTextStyle()
{
    FontSize = 16,
    TextColor = Colors.Red
};

barcode.Symbology = new Code128A() { Module = 2 };
this.Content = barcode;