Posted 12 years ago by cayenne
Version: 3.5.0421
Avatar
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">
<ListBox.ItemTemplate>
<DataTemplate>
<barCode:BarCode Height="80" Caption="{Binding Username}">
<barCode:Code128Symbology Value="{Binding Username}"/>
</barCode:BarCode>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

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 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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:
http://blogs.msdn.com/nickkramer/archive/2006/08/18/705116.aspx

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 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 12 years ago by cayenne
Avatar
Thank you for your support!
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.