{"id":392,"date":"2012-05-11T15:03:00","date_gmt":"2012-05-11T15:03:00","guid":{"rendered":"https:\/\/staging.infragistics.com\/blogs\/?p=392"},"modified":"2025-02-25T13:34:42","modified_gmt":"2025-02-25T13:34:42","slug":"creating-barcodes","status":"publish","type":"post","link":"https:\/\/www.infragistics.com\/blogs\/creating-barcodes","title":{"rendered":"Creating Barcodes With or Without Human-Readable Text With the Xambarcode"},"content":{"rendered":"\n<p>Parallel lines with varying width and spacing \u2013 they are virtually everywhere. Barcodes have a rather long history of becoming a standard for assigning data to an optical representation and it allowed for identifying a broad range of goods in stores, shipping containers and countless other items, which in turn streamlined multiple industry processes.<\/p>\n\n\n\n<p>Since barcodes are so popular and useful it\u2019s no surprise you might need to represent data in such manner in an application and Infragistics\u2019 XAML packages (<a title=\"NetAdvantage\u00ae for WPF\" href=\"http:\/\/www.infragistics.com\/dotnet\/netadvantage\/wpf.aspx#Overview\">NetAdvantage for WPF<\/a>, <a title=\"NetAdvantage\u00ae for SIlverlight\" href=\"http:\/\/www.infragistics.com\/dotnet\/netadvantage\/silverlight\/line-of-business.aspx#Overview\">Silverlight<\/a> and <a title=\"NetAdvantage\u00ae for Windows Phone\" href=\"\/support\/retired-products\">Windows Phone<\/a>) are equipped to help you with just that. The XamBarcode is just the base class really and the common name for a family of controls capable of displaying data as a graphic with lines and shapes based on various standard. There are quite a few symbologies, so if you are interested you can read extensively about them in <a title=\"NetAdvantage\u00ae Silverlight Online Help : Barcode Symbologies\" href=\"http:\/\/help.infragistics.com\/Doc\/Silverlight\/2012.1\/CLR4.0\/?page=xamBarcode_Barcode_Symbologies.html\">our documentation<\/a> (that\u2019s the Silverlight help page but the other products contain the same information too). Each of them strives to save up as much work for the developer as possible \u2013 you don\u2019t need to know the rules to create them, and in most cases you can just provide the data you want encoded and enjoy. Also each control handles just one symbology which also makes adding barcodes in XAML that much simpler (and it really is simple, you\u2019ll see below).<\/p>\n\n\n\n<p>Now there are a few special codes (like QR code) that have extra options because their non-linear structure, but most linear types like the Code 128 or Ean\/Upc codes have their data displayed just below them. With 12.1 there\u2019s a small update that allows you to hide that along with a CTP imaging library to make you \u2018bar-coding\u2019 life easier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"human-readable-text\">Human-Readable Text<\/h2>\n\n\n\n<p>That part is called very appropriately the human-readable text as the barcode is machine-readable and some standards provides us with friendly image that still carries meaning without a barcode reader.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.infragistics.com\/community\/Release\/12.1\/XAML\/XamBarcode\/human-readable_text.png\" alt=\"The human-readable part of the barcode image.\" title=\"The human-readable part of the barcode image.\"\/><\/figure>\n\n\n\n<p>While this is all very nice, there might be cases where you need just the barcode, cases where it is not required or reasonable to have that text. A new property was recently added to the controls that have such in order to be able to control if the data should be visible or waste your ink. A simple \u2018ShowText\u2019 property is now available for the following codes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Code 39<\/li>\n\n\n\n<li>Code 128<\/li>\n\n\n\n<li>Ean\/Upc<\/li>\n\n\n\n<li>Interleaved 2 Of 5<\/li>\n\n\n\n<li>GS1 DataBar<\/li>\n\n\n\n<li>Royal Mail<\/li>\n<\/ul>\n\n\n\n<p>It\u2019s a small change, but it may very well prove impactful, so let\u2019s see how to use it!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"adding-barcodes\">Adding Barcodes<\/h2>\n\n\n\n<p>Start by adding the required references \u2013 (naming is identical across the platforms) Infragistics&lt;platform&gt;.v12.1.dll, Infragistics&lt;platform&gt;.DataVisualization.v12.1.dll, Infragistics&lt;platform&gt;.Controls.Barcodes.v12.1.dll. Setting up the XamBarcode controls, providing data and controlling the human-readable text can be easily done solely in XAML via binding. For example let\u2019s have our user input the data in a field and give him some sort of a switch (toggle button, radio buttons, checkbox, etc.) to bind the \u201cShowText\u201d:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;TextBox x:Name=\"userInput\"\/>\n&lt;ToggleButton x:Name=\"textToggle\" IsChecked=\"True\">show\/hide text&lt;\/ToggleButton><\/pre>\n\n\n\n<p>And then add some Xam&lt;code&gt;Barcode controls to your page:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">xmlns:ig=\"http:\/\/schemas.infragistics.com\/xaml\"\n\n&lt;ig:XamCode39Barcode Data=\"{Binding Text, ElementName=userInput}\" ShowText=\"{Binding IsChecked, ElementName=textToggle}\" \/>\n&lt;ig:XamCode128Barcode Data=\"{Binding Text, ElementName=userInput}\" ShowText=\"{Binding IsChecked, ElementName=textToggle}\" Grid.Column=\"1\"\/>\n&lt;ig:XamEanUpcBarcode Data=\"{Binding Text, ElementName=userInput}\" ShowText=\"{Binding IsChecked, ElementName=textToggle}\" Grid.Column=\"2\"\/>\n&lt;ig:XamInterleaved2Of5Barcode Data=\"{Binding Text, ElementName=userInput}\" ShowText=\"{Binding IsChecked, ElementName=textToggle}\" Grid.Row=\"1\" \/>\n&lt;ig:XamGs1DataBarBarcode Data=\"{Binding Text, ElementName=userInput}\" ShowText=\"{Binding IsChecked, ElementName=textToggle}\" Grid.Row=\"1\" Grid.Column=\"1\"\/>\n&lt;ig:XamRoyalMailBarcode Data=\"{Binding Text, ElementName=userInput}\" ShowText=\"{Binding IsChecked, ElementName=textToggle}\" Grid.Row=\"1\" Grid.Column=\"2\"\/><\/pre>\n\n\n\n<p>After some arrangement and styling the demo can looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.infragistics.com\/community\/Release\/12.1\/XAML\/XamBarcode\/Barcodes_with_human-readble_text.png\" alt=\"Demo application with multiple barcode controls all with their 'ShowText' property boung to a toggle button.\" title=\"Demo application with multiple barcode controls all with their 'ShowText' property boung to a toggle button.\"\/><\/figure>\n\n\n\n<p>There are some additional buttons I\u2019ve added and will comment on them below, but for now we are interested in the \u2018show\u2019hide\u2019 toggle button that when unchecked will cause all barcodes to loose their text:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.infragistics.com\/community\/Release\/12.1\/XAML\/XamBarcode\/Barcodes_without_human-readble_text.png\" alt=\"Demo application with multiple barcode controls all with their text hidden.\" title=\"Demo application with multiple barcode controls all with their text hidden.\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"making-the-most-of-it\">Making the Most of It<\/h2>\n\n\n\n<p>Besides letting the user control what happens with the text, you could set that in code as well and there are some interesting applications for that as well. What you can do is display barcodes to the user with their readable data and then hide it just before printing or the other way around! Here\u2019s how that would look in a WPF application (note we have a whole bunch of barcodes so we just switch the toggle button to affect all of them, but the barcode controls can be used instead):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">private void PrintButton_Click(object sender, RoutedEventArgs e)\n {\n     \/\/print document\n     PrintDialog printDialog = new PrintDialog();\n     if (printDialog.ShowDialog() == true)\n     {\n         \/\/turn text off if it's visible\n         if (this.textToggle.IsChecked == true)\n         {\n             this.textToggle.IsChecked = false;\n             _changed = true;\n         }\n         \/\/print\n         printGrid.Measure(new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight));\n         printGrid.Arrange(new Rect(10,10,printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight));\n         printDialog.PrintVisual(printGrid, \"Barcodes Docs\");\n \n         \/\/ set text back on if it was removed for printing\n         if (_changed)\n         {\n             this.textToggle.IsChecked = true;\n             _changed = false;\n         }\n     }\n }<\/pre>\n\n\n\n<p>Also the CTP feature I mentioned that is meant to help Silverlight applications encode images \u2013 you can use that too! Let the user save an image of the barcodes in the application with or without the text and you could also control the quality of the image:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using (Stream stream = saveDialog.OpenFile())\n {\n     Infragistics.Imaging.JpegImageEncoder jpgEncoder = new Infragistics.Imaging.JpegImageEncoder();\n     List&lt;EncodingProperty> qualityList = new List&lt;EncodingProperty>();\n     qualityList.Add(new JpegQualityProperty() { Quality = 100 });\n     jpgEncoder.Encode(bitmap, qualityList, stream);\n }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>There\u2019s no doubt barcodes are useful \u2013 they can be data-packed, they can streamline and organize processes and they are everywhere. Using the XAML Barcode controls you can integrate such popular functionality in your application with great ease. Now you have even more control to the visuals of the linear barcodes with human-readable text \u2013 you can show or hide it to properly present it to the user or for printing or saving to an image!<\/p>\n\n\n\n<p><em>You can download the <strong>Demos<\/strong> shown above for <\/em><a title=\"A Silverlight demo project with various barcodes, printing and saving as image.\" href=\"http:\/\/media.infragistics.com\/community\/Release\/12.1\/XAML\/XamBarcode\/XamBarcode.zip\"><em>Silverlight<\/em><\/a><em> and <\/em><a title=\"A WPF demo project with various barcodes, printing and saving as image.\" href=\"http:\/\/media.infragistics.com\/community\/Release\/12.1\/XAML\/XamBarcode\/XamBarcodeWPF.zip\"><em>WPF<\/em><\/a><em>! Also you can see all the different types of codes in action visiting our <\/em><a title=\"Silverlight Online Samples: Barcode\" href=\"\/samples\/silverlight\/barcode\/overview\"><em>Silverlight Online Samples<\/em><\/a><em>! And you can download the WPF ones from the link above and find the Windows Phone samples in the Market.<\/em><\/p>\n\n\n\n<p><em>Follow us on Twitter <\/em><a title=\"Infragistics on Twitter\" href=\"https:\/\/twitter.com\/infragistics\" rel=\"noopener\"><em>@Infragistics<\/em><\/a><em> and join the competition on <\/em><a title=\"Infragistics on Facebook\" href=\"http:\/\/www.facebook.com\/infragistics\" rel=\"noopener\"><em>Facebook<\/em><\/a>&nbsp;<em>and don\u2019t forget to vote for us in the <a title=\"Code Project\u2019s Reader\u2019s Choice Awards\" href=\"http:\/\/www.codeproject.com\/script\/Surveys\/Results.aspx?srvid=1276\" rel=\"noopener\">Code Project\u2019s Reader\u2019s Choice Awards<\/a>!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Parallel lines with varying width and spacing \u2013 they are virtually everywhere. Barcodes have a rather long history of becoming a standard for assigning data to an optical representation and it allowed for identifying a broad range of goods in stores, shipping containers and countless other items, which in turn streamlined multiple industry processes. <\/p>\n","protected":false},"author":68,"featured_media":2370,"comment_status":"publish","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-392","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to"],"_links":{"self":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":3,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":2185,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/392\/revisions\/2185"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media\/2370"}],"wp:attachment":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}