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
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;
|