In This Article

Getting Started with Barcodes

This topic walks through adding a barcode into an application UI with the BarcodePresenter control.

Basic Setup

A minimal barcode needs:

  1. A BarcodePresenter control instance.
  2. A symbology object, such as Code128Symbology.
  3. The BarcodePresenter.Value property set to the data to encode.
xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<UserControl>
	<UserControl.Resources>
		<actipro:Code128Symbology x:Key="Code128Symbology" />
	</UserControl.Resources>

	<actipro:BarcodePresenter
		Symbology="{StaticResource Code128Symbology}"
		Value="HELLO123"
		/>
</UserControl>

Presenter and Symbology Responsibilities

Screenshot

Sample barcodes highlighting which parts are defined by BarcodePresenter compared to the Symbology

There are two key components to defining a barcode:

  • Symbology classes encode values and expose format-specific options.
  • The BarcodePresenter control handles display and presentation settings, including brushes, gradients, value appearance, and any styling accents supported by the symbology in use.

Screenshot

QR Codes support the standard appearance as well as optional stylistic variations

For example, QrCodeSymbology has options for error correction, version, finder shapes, etc. While linear symbologies share options from LinearBarcodeSymbologyBase and have their own options per symbology.

Reuse Symbology Instances

Symbologies are stateless and designed to be reused across multiple presenters.

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<!-- Code128Symbology defined in XAML resources elsewhere -->
<StackPanel Spacing="20">
	<actipro:BarcodePresenter Value="CODE001" Symbology="{StaticResource Code128Symbology}" />
	<actipro:BarcodePresenter Value="CODE002" Symbology="{StaticResource Code128Symbology}" />
	<actipro:BarcodePresenter Value="CODE003" Symbology="{StaticResource Code128Symbology}" />
</StackPanel>
Tip

Reusing a single symbology instance prevents duplication of the work needed to create that symbology's encoding tables. It also means a single instance of those tables will be stored.

Setting Properties

Set presentation-related properties on BarcodePresenter:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<actipro:BarcodePresenter
	Symbology="{StaticResource Code128Symbology}"
	Value="SAMPLE123"
	Header="Product Code"
	ZoomLevel="2"
	/>

See the Presenter Customization topic for additional details and examples.

Tip

When displayed on screen, a ZoomLevel of 2 or higher is recommended for optimal decoding by a reader, especially when DPI settings could cause anti-aliasing near pixel boundaries.

A Header is completely optional.

Set encoding-related properties on the symbology object:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<Application.Resources>
	<actipro:Code128Symbology x:Key="Code128Symbology" BarHeight="30" />
</Application.Resources>
xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<Application.Resources>
	<actipro:QrCodeSymbology x:Key="QrSymbology" ErrorCorrectionLevel="Medium" Version="Auto" />
</Application.Resources>

See the various symbology topics such as QR Code Symbologies and Linear Symbologies for details on properties supported by each symbology.

Value and Supplement Value

Use BarcodePresenter.Value for the primary value.

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<actipro:BarcodePresenter Symbology="{StaticResource Code128Symbology}" Value="123456789" />

Some symbologies like the EAN and UPC variations support BarcodePresenter.SupplementValue:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<actipro:BarcodePresenter
	Symbology="{StaticResource Ean13Symbology}"
	Value="9780134685991"
	SupplementValue="01"
	/>