Class SfBarcodeGenerator
The SfBarcodeGenerator is a data visualization control that used to generate and display data in a machine-readable format. Generally, there are two types of barcodes available. They are 1D(One Dimensional) and 2D(Two Dimensional) barcode.
Inheritance
Implements
Namespace: Syncfusion.Maui.Barcode
Assembly: Syncfusion.Maui.Barcode.dll
Syntax
public class SfBarcodeGenerator : View, IContentView, IView, IElement, ITransform, IPadding, ICrossPlatformLayout, IParentThemeElement, IThemeElement
Examples
The below examples shows, how to initialize the barcode generator.
<barcode:SfBarcodeGenerator Value="www.syncfusion.com"
ShowText="True"
HeightRequest="200"
BackgroundColor="White">
<barcode:SfBarcodeGenerator.Symbology>
<barcode:QRCode />
</barcode:SfBarcodeGenerator.Symbology>
<barcode:SfBarcodeGenerator.TextStyle>
<barcode:BarcodeTextStyle FontSize = "15" />
</ barcode:SfBarcodeGenerator.TextStyle>
</barcode:SfBarcodeGenerator>
Constructors
SfBarcodeGenerator()
Initializes a new instance of the SfBarcodeGenerator class.
Declaration
public SfBarcodeGenerator()
Remarks
Examples
The below examples shows, how to initialize the barcode generator.
<barcode:SfBarcodeGenerator Value="www.syncfusion.com"
HeightRequest="150">
</barcode:SfBarcodeGenerator>
Fields
ForegroundColorProperty
Identifies the ForegroundColor bindable property.
Declaration
public static readonly BindableProperty ForegroundColorProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ForegroundColor bindable property. |
ShowTextProperty
Identifies the ShowText bindable property.
Declaration
public static readonly BindableProperty ShowTextProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ShowText bindable property. |
SymbologyProperty
Identifies the Symbology bindable property.
Declaration
public static readonly BindableProperty SymbologyProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for Symbology bindable property. |
TextAlignmentProperty
Identifies the TextAlignment bindable property.
Declaration
public static readonly BindableProperty TextAlignmentProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for TextAlignment bindable property. |
TextSpacingProperty
Identifies the TextSpacing bindable property.
Declaration
public static readonly BindableProperty TextSpacingProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for TextSpacing bindable property. |
TextStyleProperty
Identifies the TextStyle bindable property.
Declaration
public static readonly BindableProperty TextStyleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for TextStyle bindable property. |
ValueProperty
Identifies the Value bindable property.
Declaration
public static readonly BindableProperty ValueProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for Value bindable property. |
Properties
ForegroundColor
Gets or sets the value that represents color of barcode elements.
Declaration
public Color ForegroundColor { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.Graphics.Color | The default value is |
Remarks
Color to be used when painting a vertical bar on a one-dimensional barcode and a dot on a two-dimensional barcode. This color is not used when painting a human readable text.
Examples
<barcode:SfBarcodeGenerator Value="123456"
ForegroundColor="Red"/>
ShowText
Gets or sets a value to indicate whether to show a human readable text (input value) along with a barcode.
Declaration
public bool ShowText { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | true if the value shown at the bottom of the barcode; otherwise, false.The default value is false. |
Remarks
ShowText is true
then the spacing between text and barcode is controlled by the TextSpacing property.
Examples
<barcode:SfBarcodeGenerator Value="123456"
ShowText="True"/>
Symbology
Gets or sets the instance of SymbologyBase that will be used to encode the input value to the visual barcode representation.
Declaration
public SymbologyBase Symbology { get; set; }
Property Value
Type | Description |
---|---|
SymbologyBase | The default symbology is Code128. |
Remarks
You can generate one-dimensional barcode symbologies such as Code128, Code128A, Code128B, Code128C, EAN8, EAN13, UPCA, UPCE, Code39, Code39Extended, Code93, and Codabar.
Also, you can generate two-dimensional barcode symbologies such as QRCode and DataMatrix.
Examples
<barcode:SfBarcodeGenerator Value="123456" >
<barcode:SfBarcodeGenerator.Symbology>
<barcode:UPCE />
</barcode:SfBarcodeGenerator.Symbology>
</barcode:SfBarcodeGenerator>
See Also
TextAlignment
Gets or sets the placement (start, center or end) of the text relative to its position.
Declaration
public TextAlignment TextAlignment { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.TextAlignment | The default value is |
Remarks
The barcode TextAlignment property accepts only three enum values
TextAlignment.Center
, TextAlignment.Start
and TextAlignment.End
.
TextAlignment.Center
- Align the text in the center of the barcode.
TextAlignment.Start
- Align the text on the left edge of the barcode.
TextAlignment.End
- Align the text on the right edge of the barcode.
Examples
<barcode:SfBarcodeGenerator Value="123456"
ShowText="True"
TextAlignment="End"/>
TextSpacing
Gets or sets a value to specify the space between the text and the barcode.
Declaration
public double TextSpacing { get; set; }
Property Value
Type | Description |
---|---|
System.Double | The default is |
Remarks
Based on space, the barcode height is to be reduced and the space unit is to be determined by logical pixels.
Examples
<barcode:SfBarcodeGenerator Value="123456"
ShowText="True"
TextAlignment="End"
TextSpacing="10"/>
TextStyle
Gets or sets a value to customize human readable text in barcode.
Declaration
public BarcodeTextStyle TextStyle { get; set; }
Property Value
Type | Description |
---|---|
BarcodeTextStyle | The defaults to the style that use for BarcodeTextStyle. |
Examples
<barcode:SfBarcodeGenerator Value="123456" ShowText="True">
<barcode:SfBarcodeGenerator.TextStyle>
<barcode:BarcodeTextStyle FontSize = "16" />
</ barcode:SfBarcodeGenerator.TextStyle>
</barcode:SfBarcodeGenerator>
See Also
Value
Gets or sets the value of the SfBarcodeGenerator to be rendered, which is displayed below the Barcode element when ShowText property is enabled.
Declaration
public string Value { get; set; }
Property Value
Type | Description |
---|---|
System.String | The default value is |
Remarks
The Value property is displayed below the Barcode element. The value is accepted as string and encoded in machine readable format. The spacing between the Value and barcode element is handled by TextSpacing property.
Examples
<barcode:SfBarcodeGenerator Value="123456" />
See Also
Methods
GetStreamAsync(ImageFileFormat)
To convert a barcode view to a stream, the GetStreamAsync method is used. Currently, the supported file formats are JPEG and PNG .
To get the stream for the barcode view in PNG file format, use await barcode.GetStreamAsync(ImageFileFormat.Png);
To get the stream for the barcode view in JPEG file format, use await barcode.GetStreamAsync(ImageFileFormat.Jpeg);
imageFileFormat Pass the required file format.
Declaration
public Task<Stream> GetStreamAsync(ImageFileFormat imageFileFormat)
Parameters
Type | Name | Description |
---|---|---|
ImageFileFormat | imageFileFormat | Pass the required file format. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.IO.Stream> | Returns the barcode view's stream in the desired file format. |
OnBindingContextChanged()
Invoked whenever the binding context of the View changes.
Declaration
protected override void OnBindingContextChanged()
SaveAsImage(String)
To save a barcode view as an image in the desired file format, the SaveAsImage is used. Currently, the supported image formats are JPEG and PNG .
By default, the image format is PNG. For example, barcode.SaveAsImage("Test");
To save a barcode view in the PNG image format, the filename should be passed with the ".png" extension while to save the image in the JPEG image format, the filename should be passed with the ".jpeg" extension , for example, "barcode.SaveAsImage("Test.png")" and "barcode.SaveAsImage("Test.jpeg")" respectively.
Saved location: For Windows, Android, and Mac , the image will be saved in the Pictures folder , and for iOS , the image will be saved in the Photos Album folder .
In Windows and Mac , when you save an image with an already existing filename, the existing file is replaced with a new file, but the filename remains the same.
In Android , when you save the same view with an existing filename, the new image will be saved with a filename with a number appended to it, for example, Test(1).jpeg and the existing filename Test.jpeg will be removed.When you save a different view with an already existing filename, the new image will be saved with a filename with a number will be appended to it, for example, Test(1).jpeg, and the existing filename Test.jpeg will remain in the folder.
In iOS , due to its platform limitation, the image will be saved with the default filename, for example, IMG_001.jpeg, IMG_002.png and more.
Declaration
public void SaveAsImage(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName |