Posted 16 years ago by cayenne
Version: 3.5.0421
I want to bind a DataTable to a list of barcodes. I fill the DataTable and set the binding of the ListBox to the DataTable in my code. The XAML looks like this:

<ListBox Height="150" Name="listBox1" Width="225">
<barCode:BarCode Height="80" Caption="{Binding Username}">
<barCode:Code128Symbology Value="{Binding Username}"/>

The caption is bound correctly but not the value! Each barcode has only the default value. How can I bind the barcode value to my DataTable?

[Modified at 03/19/2008 09:39 AM]

Comments (3)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
I did some investigation into this for a while and it turns out that this is a known issue in Microsoft's binding code. This article explains it pretty well:

Apparently they have not fixed it yet. The gist is that if you look your console output you will see errors like:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Width; DataItem=null; target element is 'Code128Symbology' (HashCode=8717356); target property is 'Value' (type 'String')

Because of what Nick describes in that article, the symbology is not able to properly bind to the data context.

I've done some tweaking of our code and the only thing I've found that makes it work is if the BarCodeSymbology class inherits FrameworkElement. I'm going to look into it more and perhaps make this change for the next maintenance release. There will have to be a breaking change or two since making that base class change will make our current Measure method conflict with UIElement.Measure. I'll post an update on this shortly.

Actipro Software Support

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
We've made the change to have BarCodeSymbology inherit from FrameworkElement for the next maintenance release. This works around the WPF data binding bug.

In addition, we have added a new QuickStart showing how BarCode can be used for data binding within a ListBox.

Actipro Software Support

Posted 16 years ago by cayenne
Thank you for your support!
The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.