How To: Barcode WPF DataBinding to XML Source
Technologies used
-
Neodynamic Barcode Professional for WPF (any version)
-
Microsoft .NET Framework 3.0 or greater
-
Microsoft Visual Studio 2008
-
Microsoft Visual Basic 2008 Express Edition
-
Microsoft Visual C# 2008 Express Edition
|
This walkthrough illustrates how easily you can bind Barcode
Professional to XML data in WPF Applications Barcode Professional for WPF
supports both DataBinding model i.e. XAML declarative DataBinding
syntax as well as binding in code. In this walkthrough we'll use XAML
DataBinding syntax.
The data source for our data binding sample will be a simple
XML file storing Tech Books info such as Title, Summary, ISBN (International
Standard Book Number) code and Cover Image.
During the course of this walkthrough, you will accomplish the
following activities:
-
Create a WPF Application using Visual Studio 2008 or Express Editions.
-
Create a simple WPF Window which will display info about Books stored in an XML
file. The info will be displayed by a WPF ListBox control with custom
DataTemplate for each book.
-
Convert the ISBN code to a Barcode representation by leveraging Barcode
Professional for WPF
Please follow these steps:
-
Ensure you have installed Barcode Professional for WPF
-
Launch Visual Studio and create a new WPF Application
-
Create a new folder in your project and name it "data" (without quotes)
-
Create a new XML File inside Data folder and name it BookData.XML. After that
paste the following content:
-
Add a reference to Barcode Professional for WPF assembly
(Neodynamic.WPF.Barcode.dll)
-
Open Window.XAML file at design time, resize it to Height="350" and
Width="445". Finally, in the XAML View paste the following content:
The XAML code is very simple and straightforward. In short,
we've coded the following:
-
In the Windows.Resource section, we defined:
-
The data source XmlDataProvider which points out to data\bookdata.xml file.
-
The DataTemplate which features a BarcodeProfessional control for displaying
the ISBN code in barcode format instead of a simple string. The main
BarcodeProfessional properties to set up in this specific case are Symbology
property which was set up to Isbn (because we want to barcode ISBN numbers) and
Code property which was set up to a XAML Declarative DataBinding Expression
binding to ISBN attribute of Book XML Element through a XPath command.
-
In the main Grid control onto the Window, a ListBox control is data bound to
the static resource and template for items is set up as well.
That XAML code should look like the following figure when viewing it at design
time mode of Visual Studio 2008 or Express Editions:
WPF Barcode DataBinding at design time in Visual Studio 2008
-
That's it. Run your project from VS. You'll get something like the following
figure:
The WPF DataBinding sample featuring Barcodes
If you need more information or assistance, please contact our
.
|